home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 January / macpower199701.bin / AMUG / Publishing_19 / Alpha 6.5.sit / Tcl / Modes / latexMacros.tcl < prev    next >
Encoding:
Text File  |  1996-08-15  |  91.9 KB  |  3,192 lines  |  [TEXT/ALFA]

  1. #############################################################################
  2. #############################################################################
  3. #
  4. # latexMacros.tcl (called from latex.tcl)
  5. #
  6. #############################################################################
  7. #
  8. # Author:  Tom Scavo <trscavo@syr.edu>
  9. #
  10. #############################################################################
  11. #############################################################################
  12.  
  13. #############################################################################
  14. # Basic Commands
  15. #
  16. #############################################################################
  17.  
  18. #--------------------------------------------------------------------------
  19. # Goto:
  20. #--------------------------------------------------------------------------
  21.  
  22. # Switch to (but don't execute) any of the following applications.
  23. proc latex {} {
  24.     global texSig texAppSig
  25.     set supportedApps [array names texAppSig]
  26.     foreach app $supportedApps { lappend sigs $texAppSig($app) }
  27.     set longPrompt "Please locate your TeX app."
  28.     if { [catch {launchBackApplSigs $sigs texSig $longPrompt} appname] } {
  29.         error "bug in 'launchBackApplSigs'"
  30.     }
  31.     set quotedSig "'[string trim $texSig {'}]'"
  32.     switchTo $quotedSig
  33. }
  34. proc bibtex {} {
  35.     global bibtexSig bibtexAppSig
  36.     set supportedApps [array names bibtexAppSig]
  37.     foreach app $supportedApps { lappend sigs $bibtexAppSig($app) }
  38.     set longPrompt "Please locate your BibTeX app."
  39.     if { [catch {launchBackApplSigs $sigs bibtexSig $longPrompt} appname] } {
  40.         error "bug in 'launchBackApplSigs'"
  41.     }
  42.     set quotedSig "'[string trim $bibtexSig {'}]'"
  43.     switchTo $quotedSig
  44. }
  45. proc makeindex {} {
  46.     global makeindexSig makeindexAppSig
  47.     set supportedApps [array names makeindexAppSig]
  48.     foreach app $supportedApps { lappend sigs $makeindexAppSig($app) }
  49.     set longPrompt "Please locate your MakeIndex app."
  50.     if { [catch {launchBackApplSigs $sigs makeindexSig $longPrompt} appname] } {
  51.         error "bug in 'launchBackApplSigs'"
  52.     }
  53.     set quotedSig "'[string trim $makeindexSig {'}]'"
  54.     switchTo $quotedSig
  55. }
  56.  
  57. # Find the next or previous environment.  Search forward (or backward, 
  58. # depending on $forward) for either ¥begin or ¥end.  If ¥begin is found, 
  59. # search forward for corresponding ¥end; otherwise, search backward for 
  60. # corresponding ¥begin.  Select the found environment, or display an 
  61. # error message if no environment is found.
  62. proc findEnvironment {forward} {
  63.     set searchString1 {^[ ¥t]*¥¥begin¥{[^¥{¥}]*¥}|¥¥end¥{[^¥{¥}]*¥}[ ¥t]*¥r?}
  64.     set searchPos [getPos]
  65.     if { [isSelection] } then { 
  66.         if { $forward } then {
  67.             set searchPos [selEnd]
  68.         } else {
  69.             set searchPos [expr $searchPos - 1]
  70.         }
  71.     } else {
  72.         if { $forward } then {
  73.             set searchPos [expr $searchPos + 1]
  74.         } else {
  75.             set searchPos [expr $searchPos - 1]
  76.         }
  77.     }
  78.     set searchResult [search -s -f $forward -r 1 -n $searchString1 $searchPos]
  79.     if {[string length $searchResult]} then {
  80.         set begPos [lindex $searchResult 0]
  81.         set endPos [lindex $searchResult 1]
  82.         set searchText [getText $begPos $endPos]
  83.         regexp {¥{(.*)¥}} $searchText dummy envName
  84.         if {[string match {*begin*} $searchText]} {
  85.             set begEnv $begPos
  86.             append searchString2 {¥¥end¥{} $envName {¥}[ ¥t]*¥r?}
  87.             set searchPos $endPos
  88.             set searchResult [search -s -f 1 -r 1 -n $searchString2 $searchPos]
  89.             if {[string length $searchResult]} {
  90.                 set endPos [lindex $searchResult 1]
  91.                 return [list $begPos $endPos]
  92.             } else {
  93.                 return "matching ¥¥end not found"
  94.             }
  95.         } else {
  96.             set endEnv $endPos
  97.             append searchString2 {^[ ¥t]*¥¥begin¥{} $envName {¥}}
  98.             set searchPos $begPos
  99.             set searchResult [search -s -f 0 -r 1 -n $searchString2 $searchPos]
  100.             if {[string length $searchResult]} {
  101.                 set begPos [lindex $searchResult 0]
  102.                 return [list $begPos $endPos]
  103.             } else {
  104.                 return "matching ¥¥begin not found"
  105.             }
  106.         }
  107.     } else {
  108.         if { $forward } then {
  109.             return "next environment not found"
  110.         } else {
  111.             return "previous environment not found"
  112.         }
  113.     }
  114. }
  115.  
  116. proc prevEnvironment {} {
  117.     global searchNoisily
  118.     set findResult [findEnvironment 0]
  119.     if {[llength $findResult] == 2} then {
  120.         goto [lindex $findResult 0]
  121.     } else {
  122.         if {$searchNoisily} {beep}
  123.         message $findResult
  124.     }
  125. }
  126. proc nextEnvironment {} {
  127.     global searchNoisily
  128.     set findResult [findEnvironment 1]
  129.     if {[llength $findResult] == 2} then {
  130.         goto [lindex $findResult 0]
  131.     } else {
  132.         if {$searchNoisily} {beep}
  133.         message $findResult
  134.     }
  135. }
  136. proc prevEnvironmentSelect {} {
  137.     global searchNoisily
  138.     set forward 0
  139.     set findResult [findEnvironment $forward]
  140.     if {[llength $findResult] == 2} then {
  141.         set endPos [lindex $findResult 1]
  142. #         if { [regexp {¥r} [lookAt [expr $endPos + 1]]] } then {
  143. #             set endPos [expr $endPos + 1]
  144. #         }
  145.         select [lindex $findResult 0] $endPos
  146.     } else {
  147.         if { $searchNoisily } {beep}
  148.         message $findResult
  149.     }
  150. }
  151. proc nextEnvironmentSelect {} {
  152.     global searchNoisily
  153.     set forward 1
  154.     set findResult [findEnvironment $forward]
  155.     if {[llength $findResult] == 2} then {
  156.         set endPos [lindex $findResult 1]
  157. #         if { [regexp {¥r} [lookAt [expr $endPos + 1]]] } then {
  158. #             set endPos [expr $endPos + 1]
  159. #         }
  160.         select [lindex $findResult 0] $endPos
  161.     } else {
  162.         if { $searchNoisily } {beep}
  163.         message $findResult
  164.     }
  165. }
  166.  
  167. # Find a LaTeX command in either direction.  It's up to the calling
  168. # procedure to pass the correct starting position of the search.
  169. proc findCommand {pos direction} {
  170. #    Handle "¥ " and "¥[" separately:
  171.     set searchString {(¥¥([^a-zA-Z¥t¥r* []|[a-zA-Z]+)¥*?)|([^¥¥]¥¥¥ )|([^¥¥]¥¥¥[)}
  172.     set searchResult [search -s -f $direction -r 1 -n $searchString $pos]
  173.     if { [string length $searchResult] } {
  174.         set begPos [lindex $searchResult 0]
  175.         set endPos [lindex $searchResult 1]
  176.         set lastChar [lookAt [expr $endPos - 1]]
  177.         if {$lastChar == "¥ " || $lastChar == "¥["} then {
  178.             return [list [expr $begPos + 1] $endPos]
  179.         } else {}
  180.     }
  181.     return $searchResult
  182. # Handles everything but "¥ " and "¥[":
  183. #     set searchString {¥¥([^a-zA-Z¥t¥r* []|[a-zA-Z]+)¥*?}
  184. #     return [search -s -f $direction -r 1 -n $searchString $pos]
  185. }
  186. # Find and goto the beginning of the previous LaTeX command.
  187. proc prevCommand {} {
  188.     global searchNoisily
  189.     set pos [getPos]
  190.     if {$pos > 0} then {
  191.         set searchResult [findCommand [expr $pos - 1] 0]
  192.         if { [string length $searchResult] } {
  193.             goto [lindex $searchResult 0]
  194.             return
  195.         } else {}
  196.     }
  197.     if { $searchNoisily } {beep}
  198.     message "previous command not found"
  199. }
  200. # Find and goto the beginning of the next LaTeX command.
  201. proc nextCommand {} {
  202.     global searchNoisily
  203.     set pos [getPos]
  204.     if {$pos < [maxPos]} then {
  205.         set searchResult [findCommand [expr $pos + 1] 1]
  206.         if { [string length $searchResult] } {
  207.             goto [lindex $searchResult 0]
  208.             return
  209.         } else {}
  210.     }
  211.     if { $searchNoisily } {beep}
  212.     message "next command not found"
  213. }
  214. # Select the previous LaTeX command, but do not attempt to select
  215. # any associated argument.
  216. proc prevCommandSelect {} {
  217.     global searchNoisily
  218.     set pos [getPos]
  219.     if {$pos > 0} then {
  220.         set searchResult [findCommand [expr $pos - 1] 0]
  221.         if { [string length $searchResult] } {
  222.             eval select $searchResult
  223.             return
  224.         } else {}
  225.     }
  226.     if { $searchNoisily } {beep}
  227.     message "previous command not found"
  228. }
  229. # Select the next LaTeX command, but do not attempt to select
  230. # any associated argument.
  231. proc nextCommandSelect {} {
  232.     global searchNoisily
  233.     set pos [getPos]
  234.     if {$pos < [maxPos]} then {
  235.         if { [isSelection] } then {
  236.             set pos [expr $pos + 1]
  237.         }
  238.         set searchResult [findCommand $pos 1]
  239.         if { [string length $searchResult] } {
  240.             eval select $searchResult
  241.             return
  242.         } else {}
  243.     }
  244.     if { $searchNoisily } {beep}
  245.     message "next command not found"
  246. }
  247.  
  248. # Find a LaTeX command with arguments in either direction.  It's up 
  249. # to the calling procedure to pass the starting position of the search.
  250. # (Handles everything but "¥ " and commands whose arguments contain
  251. # embedded braces.)
  252. proc findCommandWithArgs {pos direction} {
  253.     set searchString {¥¥([^a-zA-Z¥t¥r]|[a-zA-Z]+¥*?)(¥[.*¥])*({[^{}]*})*}
  254.     return [search -s -f $direction -r 1 -n $searchString $pos]
  255. }
  256. # Select the previous LaTeX command and any associated arguments.
  257. proc prevCommandSelectWithArgs {} {
  258.     global searchNoisily
  259.     set pos [getPos]
  260.     if {$pos > 0} then {
  261.         set searchResult [findCommandWithArgs [expr $pos - 1] 0]
  262.         if { [string length $searchResult] } {
  263.             eval select $searchResult
  264.             return
  265.         } else {}
  266.     }
  267.     if { $searchNoisily } {beep}
  268.     message "previous command not found"
  269. }
  270. # Select the next LaTeX command and any associated arguments.
  271. proc nextCommandSelectWithArgs {} {
  272.     global searchNoisily
  273.     set pos [getPos]
  274.     if {$pos < [maxPos]} then {
  275.         if { [isSelection] } then {
  276.             set pos [expr $pos + 1]
  277.         }
  278.         set searchResult [findCommandWithArgs $pos 1]
  279.         if { [string length $searchResult] } {
  280.             eval select $searchResult
  281.             return
  282.         } else {}
  283.     }
  284.     if { $searchNoisily } {beep}
  285.     message "next command not found"
  286. }
  287.  
  288. # Find a LaTeX sectioning command in either direction.  It's up to 
  289. # the calling procedure to pass the starting position of the search.
  290. proc findSection {pos direction} {
  291.     global funcExprAlt
  292.     return [search -s -f $direction -r 1 -n $funcExprAlt $pos]
  293. }
  294. # Select the previous LaTeX sectioning command.
  295. proc prevSection {} {
  296.     global searchNoisily
  297.     set pos [getPos]
  298.     if {$pos > 0} then {
  299.         set searchResult [findSection [expr $pos - 1] 0]
  300.         if { [string length $searchResult] } {
  301.             eval select $searchResult
  302.             return
  303.         } else {}
  304.     }
  305.     if { $searchNoisily } {beep}
  306.     message {previous section not found}
  307. }
  308. # Select the next LaTeX sectioning command.
  309. proc nextSection {} {
  310.     global searchNoisily
  311.     set pos [getPos]
  312.     if {$pos < [maxPos]} then {
  313.         if { [isSelection] } then {
  314.             set pos [expr $pos + 1]
  315.         }
  316.         set searchResult [findSection $pos 1]
  317.         if { [string length $searchResult] } {
  318.             eval select $searchResult
  319.             return
  320.         } else {}
  321.     }
  322.     if { $searchNoisily } {beep}
  323.     message {next section not found}
  324. }
  325. proc prevSectionSelect {} {
  326.     global searchNoisily
  327.     set pos [getPos]
  328.     if {$pos > 0} then {
  329.         set searchResult [findSection [expr $pos - 1] 0]
  330.         if { [string length $searchResult] } {
  331.             set begPos [lindex $searchResult 0]
  332.             set searchPos [expr [lindex $searchResult 1] + 1]
  333.             set searchResult [findSection $searchPos 1]
  334.             if { [string length $searchResult] } {
  335.                 set endPos [lindex $searchResult 0]
  336.             } else {
  337.                 set searchResult [search -s -f 1 -r 0 -n "¥¥end{document}" $searchPos]
  338.                 set endPos [lindex $searchResult 0]
  339.             }
  340.             select $begPos $endPos
  341.             return
  342.         } else {}
  343.     }
  344.     if { $searchNoisily } {beep}
  345.     message {previous section not found}
  346. }
  347. # Select the next LaTeX sectioning command.
  348. proc nextSectionSelect {} {
  349.     global searchNoisily
  350.     set pos [getPos]
  351.     if {$pos < [maxPos]} then {
  352.         if { [isSelection] } then {
  353.             set pos [expr $pos + 1]
  354.         }
  355.         set searchResult [findSection $pos 1]
  356.         if { [string length $searchResult] } {
  357.             set begPos [lindex $searchResult 0]
  358.             set searchPos [expr [lindex $searchResult 1] + 1]
  359.             set searchResult [findSection $searchPos 1]
  360.             if { [string length $searchResult] } {
  361.                 set endPos [lindex $searchResult 0]
  362.             } else {
  363.                 set searchResult [search -s -f 1 -r 0 -n "¥¥end{document}" $searchPos]
  364.                 set endPos [lindex $searchResult 0]
  365.             }
  366.             select $begPos $endPos
  367.             return
  368.         } else {}
  369.     }
  370.     if { $searchNoisily } {beep}
  371.     message {next section not found}
  372. }
  373.  
  374. # Find a LaTeX subsectioning command in either direction.  It's up to 
  375. # the calling procedure to pass the starting position of the search.
  376. proc findSubsection {pos direction} {
  377.     global funcExpr
  378.     return [search -s -f $direction -r 1 -n $funcExpr $pos]
  379. }
  380. proc prevSubsection {} {
  381.     global searchNoisily
  382.     set pos [getPos]
  383.     if {$pos > 0} then {
  384.         set searchResult [findSubsection [expr $pos - 1] 0]
  385.         if { [string length $searchResult] } {
  386.             eval select $searchResult
  387.             return
  388.         } else {}
  389.     }
  390.     if { $searchNoisily } {beep}
  391.     message {previous (sub)*section not found}
  392. }
  393. # Select the next LaTeX sectioning command.
  394. proc nextSubsection {} {
  395.     global searchNoisily
  396.     set pos [getPos]
  397.     if {$pos < [maxPos]} then {
  398.         if { [isSelection] } then {
  399.             set pos [expr $pos + 1]
  400.         }
  401.         set searchResult [findSubsection $pos 1]
  402.         if { [string length $searchResult] } {
  403.             eval select $searchResult
  404.             return
  405.         } else {}
  406.     }
  407.     if { $searchNoisily } {beep}
  408.     message {next (sub)*section not found}
  409. }
  410. proc prevSubsectionSelect {} {
  411.     global searchNoisily
  412.     set pos [getPos]
  413.     if {$pos > 0} then {
  414.         set searchResult [findSubsection [expr $pos - 1] 0]
  415.         if { [string length $searchResult] } {
  416.             set begPos [lindex $searchResult 0]
  417.             set endPos [lindex $searchResult 1]
  418.             set searchPos [expr $endPos + 1]
  419.             set commandName [extractCommandName [getText $begPos $endPos]]
  420.             if {[string match {section*} $commandName]} then {
  421.                 set searchResult [findSection $searchPos 1]
  422.             } else {
  423.                 set searchResult [findSubsection $searchPos 1]
  424.             }
  425.             if { [string length $searchResult] } {
  426.                 set endPos [lindex $searchResult 0]
  427.             } else {
  428.                 set searchResult [search -s -f 1 -r 0 -n "¥¥end{document}" $searchPos]
  429.                 set endPos [lindex $searchResult 0]
  430.             }
  431.             select $begPos $endPos
  432.             return
  433.         } else {}
  434.     }
  435.     if { $searchNoisily } {beep}
  436.     message {previous (sub)*section not found}
  437. }
  438. # Select the next LaTeX sectioning command.
  439. proc nextSubsectionSelect {} {
  440.     global searchNoisily
  441.     set pos [getPos]
  442.     if {$pos < [maxPos]} then {
  443.         if { [isSelection] } then {
  444.             set pos [expr $pos + 1]
  445.         }
  446.         set searchResult [findSubsection $pos 1]
  447.         if { [string length $searchResult] } {
  448.             set begPos [lindex $searchResult 0]
  449.             set endPos [lindex $searchResult 1]
  450.             set searchPos [expr $endPos + 1]
  451.             set commandName [extractCommandName [getText $begPos $endPos]]
  452.             if {[string match {section*} $commandName]} then {
  453.                 set searchResult [findSection $searchPos 1]
  454.             } else {
  455.                 set searchResult [findSubsection $searchPos 1]
  456.             }
  457.             if { [string length $searchResult] } {
  458.                 set endPos [lindex $searchResult 0]
  459.             } else {
  460.                 set searchResult [search -s -f 1 -r 0 -n "¥¥end{document}" $searchPos]
  461.                 set endPos [lindex $searchResult 0]
  462.             }
  463.             select $begPos $endPos
  464.             return
  465.         } else {}
  466.     }
  467.     if { $searchNoisily } {beep}
  468.     message {next (sub)*section not found}
  469. }
  470.  
  471. proc gotoTabStop {dirIndicator} {
  472.     set pos [getPos]
  473.     if {$dirIndicator} then {
  474.         if {$pos == [maxPos]} { return 0 }
  475.     } else {
  476.         if {$pos == 0} { return 0 }
  477.         # Fixes a bug in 'search':
  478.         set pos [expr $pos - 1]
  479.     }
  480.     set searchResult [search -s -n -f $dirIndicator -m 0 -i 1 -r 0 {・} $pos]
  481.     if {[string length $searchResult]} then {
  482.         goto [lindex $searchResult 0]
  483.         return 1
  484.     } else {
  485.         return 0
  486.     }
  487. }
  488. proc nextTabStop {} {
  489.     global searchNoisily
  490.     set forward 1
  491.     if { [gotoTabStop $forward] } then {
  492.         deleteChar
  493.     } else {
  494.         if { $searchNoisily } {beep}
  495.         message "tab stop not found"
  496.     }
  497. }
  498. proc prevTabStop {} {
  499.     global searchNoisily
  500.     set forward 0
  501.     if { [gotoTabStop $forward] } then {
  502.         deleteChar
  503.     } else {
  504.         if { $searchNoisily } {beep}
  505.         message "tab stop not found"
  506.     }
  507. }
  508. # Goto the nth tab stop.  A nonzero argument is non-interactive
  509. # (for use in Tcl procs) and not validated.
  510. proc nthTabStop {{numTabStops 0}} {
  511.     global searchNoisily promptNoisily useStatusBar
  512.     if { $numTabStops == 0 } then {
  513.         if { $promptNoisily && $useStatusBar } { beep }
  514.         catch {sPrompt "How many tab stops?" "3"} numTabStops
  515.         if { $numTabStops == "cancel" || $numTabStops == 0 } then {
  516.             return
  517.         } elseif { ![isInteger $numTabStops] } then {
  518.             beep
  519.             message "invalid input:  integer required"
  520.             return
  521.         }
  522.     }
  523.     set currentPos [getPos]
  524.     if { $numTabStops > 0 } { set forward 1 } { set forward 0 }
  525.     set maxits [expr abs($numTabStops)]
  526.     if { ![gotoTabStop $forward] } then {
  527.         if { $searchNoisily } {beep}
  528.         message "tab stop not found"
  529.         goto $currentPos
  530.         return
  531.     }
  532.     for { set i 1 } { $i < $maxits } { incr i } {
  533.         if { $forward } { forwardChar } { backwardChar }
  534.         if { ![gotoTabStop $forward] } then {
  535.             if { $searchNoisily } { beep }
  536.             message "tab stop not found"
  537.             goto $currentPos
  538.             return
  539.         }
  540.     }
  541.     deleteChar
  542. }
  543.  
  544. #--------------------------------------------------------------------------
  545. # Utilities:
  546. #--------------------------------------------------------------------------
  547.  
  548. # A keyboard-bound method of accessing menu commands.  Takes a list of 
  549. # menu items (i.e., the tail of a 'menu' command), the menu name (the 
  550. # argument of the '-n' switch) , and the name of a menu filter (the 
  551. # argument of the '-p' switch) as input, and displays these items in a 
  552. # list box.  If the chosen item is a menu command (as opposed to a 
  553. # submenu), it is passed to the menu filter; otherwise, 'chooseCommand' 
  554. # recursively calls itself until a menu command is chosen or the cancel 
  555. # button is pressed.
  556. #
  557. proc chooseCommand {menuItems {menuName ""} {menuFilterProc ""} {level 1}} {
  558.     watchCursor
  559.     if { $menuItems == "" } { return }
  560.     # Preprocess the list of menu items:
  561.     foreach    item $menuItems {
  562.         regsub -all {[<!/].} $item {} item
  563.         regsub -all {ノ}    $item {} item
  564.         lappend    menOut $item
  565.         if { [string match "menu*" $item] } {
  566.             if { [set ind [lsearch $item {-n}]] >= 0 } {
  567.                 lappend    top "[lindex $item [incr    ind]]:"
  568.             }
  569.         } elseif { ![string match "(*" $item] } {
  570.             lappend    top $item
  571.         }
  572.     }
  573.     # Present the menu items to the user:
  574.     set res    [listpick -p "Choose menu command (level $level):" $top]
  575.     # Either execute a command or recurse on a submenu:
  576.     if { [lsearch $menOut $res] >= 0 } {
  577.         # Execute the command via the menu filter, if necessary:
  578.         if { $menuFilterProc == "" } {
  579.             $res
  580.         } else {
  581.             $menuFilterProc $menuName $res
  582.         }
  583.     } else {
  584.         set res [string trimright $res {:}]
  585.         foreach    item $menOut {
  586.             if { [lsearch $item $res] >= 0 } {
  587.                 set menuItems [lindex $item end]
  588.                 # Determine the name of this submenu:
  589.                 if { [set ind [lsearch $item {-n}]] >= 0 } {
  590.                     set menuName [lindex $item [incr ind]]
  591.                 } else {
  592.                     set menuName ""
  593.                 }
  594.                 # Determine the name of the menu filter for this submenu:
  595.                 if { [set ind [lsearch $item {-p}]] >= 0 } {
  596.                     set menuFilterProc [lindex $item [incr ind]]
  597.                 } else {
  598.                     set menuFilterProc ""
  599.                 }
  600.                 return [chooseCommand $menuItems $menuName $menuFilterProc [incr level]]
  601.             }
  602.         }
  603.     }
  604. }
  605.  
  606. proc insertLiteralTab {} {
  607.     if {[isSelection]} then {
  608.         deleteSelection
  609.     }
  610.     insertText "¥t"
  611. }
  612.  
  613. proc insertTabStop {} {
  614.     if {[isSelection]} then {
  615.         deleteSelection
  616.     }
  617.     insertText "・"
  618. }
  619.  
  620. # Removes all tab stops from the current selection (if there is one) 
  621. # or the current document, maintaining the cursor position in the 
  622. # latter case.
  623. proc deleteTabStops {} {
  624.     global searchNoisily
  625.     watchCursor
  626.     set subs1 0; set subs2 0; set subs3 0
  627.     set pos [getPos]
  628.     if {[set start $pos] == [set end [selEnd]]} {
  629.         set messageString "document"
  630.         set start 0
  631.         set end [maxPos]
  632.         set text1 [getText $start $pos]
  633.         set subs1 [regsub -all {・} $text1 {} text1]
  634.         set text2 [getText $pos $end]
  635.         set subs2 [regsub -all {・} $text2 {} text2]
  636.         append text $text1 $text2
  637.     } else {
  638.         set messageString "selection"
  639.         set text [getText $start $end]
  640.         set subs3 [regsub -all {・} $text {} text]
  641.     }
  642.     if {$subs1 || $subs2 || $subs3} then {
  643.         replaceText $start $end $text
  644.         if {$messageString == "document"} then {
  645.             goto [expr $pos - $subs1]
  646.         } else {
  647.             set end [getPos]
  648.             select $start $end
  649.         }
  650.         set subs [expr $subs1 + $subs2 + $subs3]
  651.         message "$subs tab stops removed from $messageString"
  652.     } else {
  653.         if {$searchNoisily} {beep}
  654.         message "no tab stops found in $messageString"
  655.     }
  656. }
  657.  
  658. # Delete all unnecessary comments from the current document:
  659. proc deleteComments {} {
  660.     switch [askyesno "Warning!  This operation can not be undone.  ¥
  661.                     Continue anyway?"] {
  662.         "yes" {}
  663.         "no" { return }
  664.     }
  665.     replaceString {}
  666.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {^[ ¥t]*%.*¥r} 0]
  667.     replaceAll
  668.     
  669.     replaceString {}
  670.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {[ ¥t]+%.*} 0]
  671.     replaceAll
  672.     
  673.     replaceString {¥1%}
  674.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {([^¥¥](¥¥¥¥)*)%.*} 0]
  675.     replaceAll
  676. }
  677.  
  678. # Converts all straight quotes to their TeX equivalents.
  679. proc convertQuotes {} {
  680.     global searchNoisily
  681.     message "workingノ"
  682.     watchCursor
  683.     set messageString "selection"
  684.     if {[set start [getPos]] == [set end [selEnd]]} {
  685.         set messageString "document"
  686.         set start 0
  687.         set end [maxPos]
  688.     }
  689.     set text [getText $start $end]
  690.     # Convert all left double quotes:
  691.     set convert1 [regsub -all "¥(¥^¥|¥[¥ ¥r¥t¥(¥[¥{¥]¥)¥"" $text {¥1``} text]
  692.     # Convert all right double quotes:
  693.     set convert2 [regsub -all "¥(¥[¥^¥¥¥¥¥]¥)¥"" $text {¥1''} text]
  694.     # Convert all left single quotes:
  695.     set convert3 [regsub -all "¥(¥^¥|¥[¥ ¥r¥t¥(¥[¥{¥]¥)¥'" $text {¥1`} text]
  696.     if {$convert1 || $convert2 || $convert3} then {
  697.         replaceText $start $end $text
  698.         message "all quotes in $messageString converted"
  699.     } else {
  700.         if {$searchNoisily} {beep}
  701.         message "no quotes found in $messageString"
  702.     }
  703. }
  704.  
  705. # Returns true if the argument contains non-literal double dollar
  706. # signs, and false otherwise.
  707. proc containsDoubleDollarSigns {text} {
  708.     return [regexp {(^|[^¥¥])¥$¥$} $text]
  709. }
  710.  
  711. # Converts all $$...$$ pairs to ¥[...¥] and returns the number of such 
  712. # pairs converted.  If the dollar signs are unbalanced, does nothing 
  713. # and returns -1.
  714. proc convertDoubleDollarSigns {} {
  715.     watchCursor
  716.     set messageString "selection"
  717.     if {[set start [getPos]] == [set end [selEnd]]} {
  718.         set messageString "document"
  719.         set start 0
  720.         set end [maxPos]
  721.     }
  722.     set text [getText $start $end]
  723.     set subs [regsub -all {(^|[^¥¥])¥$¥$([^$]*)¥$¥$} $text {¥1¥¥[¥2¥¥]} text]
  724.     if {[containsDoubleDollarSigns $text]} then {return -1}
  725.     if {$subs} then {
  726.         replaceText $start $end $text
  727.     }
  728.     return [expr $subs]
  729. }
  730.  
  731. # Returns true if the argument contains a non-literal dollar sign,
  732. # and false otherwise.
  733. proc containsSingleDollarSign {text} {
  734.     return [regexp {(^|[^¥¥])¥$} $text]
  735. }
  736.  
  737. # Converts all $...$ pairs to ¥(...¥), maintains the cursor position, 
  738. # and returns the number of such pairs converted.  If the dollar signs 
  739. # are unbalanced, does nothing and returns -1.
  740. proc convertSingleDollarSigns {} {
  741.     watchCursor
  742.     set subs1 0; set subs2 0; set subs3 0
  743.     set pos [getPos]; set pos2 $pos
  744.     if {[set start $pos] == [set end [selEnd]]} {
  745.         set isSelection 0
  746.         set start 0
  747.         set end [maxPos]
  748.         set text1 [getText $start $pos]
  749.         set subs1 [regsub -all {(^|[^¥¥])¥$([^$]*)¥$} $text1 {¥1¥¥(¥2¥¥)} text1]
  750.         # Is there a dollar sign left over?  If so, search backward for this
  751.         # dollar sign and prepare to do a substitution on the text to the right
  752.         # of this dollar sign.
  753.         if {[containsSingleDollarSign $text1]} then {
  754.             set searchString {[^¥¥]¥$}
  755.             set searchResult [search -s -n -f 0 -m 0 -i 1 -r 1 $searchString [expr $pos-1]]
  756.             set pos2 [lindex $searchResult 0]
  757.             set text1 [string range $text1 0 [expr $pos2 + (2 * $subs1)]]
  758.             set pos [expr $pos + 2]
  759.         }
  760.         set text2 [getText $pos2 $end]
  761.         set subs2 [regsub -all {(^|[^¥¥])¥$([^$]*)¥$} $text2 {¥1¥¥(¥2¥¥)} text2]
  762.         # Is there a dollar sign left over?  If so, it's unbalanced.
  763.         if {[containsSingleDollarSign $text2]} then {return -1}
  764.         append text $text1 $text2
  765.     } else {
  766.         set isSelection 1
  767.         set text [getText $start $end]
  768.         set subs3 [regsub -all {(^|[^¥¥])¥$([^$]*)¥$} $text {¥1¥¥(¥2¥¥)} text]
  769.         # Is there a dollar sign left over?  If so, it's unbalanced.
  770.         if {[containsSingleDollarSign $text]} then {return -1}
  771.     }
  772.     if {$subs1 || $subs2 || $subs3} then {
  773.         replaceText $start $end $text
  774.         # If there is a selection, just put it back.  Otherwise, adjust the
  775.         # cursor position based on the number of substitutions.
  776.         if {$isSelection} then {
  777.             set end [getPos]
  778.             select $start $end
  779.         } else {
  780.             goto [expr $pos + (2 * $subs1)]
  781.         }
  782.     }
  783.     return [expr $subs1 + $subs2 + $subs3]
  784. }
  785.  
  786. proc convertDollarSigns {} {
  787.     global searchNoisily
  788.     if {[isSelection]} then {
  789.         set messageString "selection"
  790.     } else {
  791.         set messageString "document"
  792.     }
  793.     set subs2 [convertDoubleDollarSigns]
  794.     if {$subs2 == -1} then {
  795.         beep
  796.         alertnote "unmatched double dollar signs in $messageString"
  797.     } else {
  798.         set subs1 [convertSingleDollarSigns]
  799.         if {$subs1 == -1} then {
  800.             beep
  801.             alertnote "unmatched single dollar sign in $messageString"
  802.         } elseif {$subs1 == 0 && $subs2 == 0} then {
  803.             if {$searchNoisily} {beep}
  804.             message "no dollar signs found in $messageString"
  805.         } else {
  806.             message "$subs1 pairs of ¥$ノ¥$ and $subs2 pairs of ¥$¥$ノ¥$¥$ removed from $messageString"
  807.         }
  808.     }
  809. }
  810.  
  811.  
  812. #############################################################################
  813. # Paragraph Mode Macros
  814. #
  815. #############################################################################
  816.  
  817. #--------------------------------------------------------------------------
  818. # Documents:
  819. #--------------------------------------------------------------------------
  820.  
  821. proc newLaTeXDocument {} {
  822.     catch {prompt "Choose a documentclass:" "article" "" "article" ¥
  823.             "report" "book" "letter" "slides"} documentType
  824.     if {$documentType != "cancel"} then {
  825.         new
  826.         newMode TeX
  827.         if { [catch {${documentType}Documentclass}] } then {
  828.             wrapDocument "$documentType" 
  829.         }
  830.         while { [options] } {}
  831.         nextTabStop
  832.         message "enter option (or leave blank)"
  833.     }
  834. }
  835.  
  836. proc letterDocumentclass {} {
  837.     set    preamble "¥r¥¥address¥{%¥r"
  838.     append preamble "    ・    ¥¥¥¥    % insert your name here¥r"
  839.     append preamble "    ・    ¥¥¥¥    % insert your address here¥r"
  840.     append preamble "    ・    ¥¥¥¥    % insert more address here¥r"
  841.     append preamble "    ・          % insert city-state-zip here¥r"
  842.     append preamble "¥}¥r¥r"
  843.     append preamble "¥¥date¥{・¥}  % optional¥r"
  844.     append preamble "¥¥signature¥{・¥}¥r¥r"
  845.     set    body     "¥r¥¥begin¥{letter¥}¥{%¥r"
  846.     append body     "    ・    ¥¥¥¥    % insert addressee's name here¥r"
  847.     append body     "    ・    ¥¥¥¥    % insert addressee's address here¥r"
  848.     append body     "    ・    ¥¥¥¥    % insert more address here¥r"
  849.     append body     "    ・          % insert addressee's city-state-zip here¥r"
  850.     append body     "¥}¥r¥r"
  851.     append body     "¥¥opening¥{Dear ・,¥}¥r¥r"
  852.     if {[isEmptyFile]} then {
  853.         append body "% BODY OF LETTER¥r"
  854.         append body "・¥r¥r"
  855.     } else {
  856.         if {[isDocumentSelected]} then {
  857.             set text [getSelect]
  858. #             deleteText 0 [maxPos]
  859.             append body "$text¥r"
  860.         } else {
  861.             alertnote "nonempty file:  delete text or ¥'Select All¥'¥
  862.                 from the Edit menu"
  863.             return
  864.         }
  865.     }
  866.     append body "¥¥closing¥{Sincerely,¥}¥r¥r"
  867.     append body "¥¥encl¥{・¥}¥r"
  868.     append body "¥¥cc¥{・¥}¥r¥r"
  869.     append body "¥¥end¥{letter¥}¥r¥r"
  870.     insertDocument "letter" $preamble $body
  871.     nextTabStop
  872.     message "enter option (or leave blank)"
  873. }
  874. proc articleDocumentclass {} {
  875.     if { [wrapDocument "article"] } {
  876.         nextTabStop
  877.         message "enter option (or leave blank)"
  878.     }
  879. }
  880. proc reportDocumentclass {} {
  881.     if { [wrapDocument "report"] } {
  882.         nextTabStop
  883.         message "enter option (or leave blank)"
  884.     }
  885. }
  886. proc bookDocumentclass {} {
  887.     if { [wrapDocument "book"] } {
  888.         nextTabStop
  889.         message "enter option (or leave blank)"
  890.     }
  891. }
  892. proc slidesDocumentclass {} {
  893.     if { [wrapDocument "slides"] } {
  894.         nextTabStop
  895.         message "enter option (or leave blank)"
  896.     }
  897. }
  898. proc otherDocumentclass {} {
  899.     catch {prompt "What documentclass?" "article"} documentType
  900.     if {$documentType != "cancel"} then {
  901.         if { [wrapDocument "$documentType"] } {
  902.             nextTabStop
  903.             message "enter option (or leave blank)"
  904.         }
  905.     }
  906. }
  907.  
  908. # If an option is inserted, return true; otherwise, return false.
  909. proc options {} {
  910.     set option [getOption]
  911.     if {$option != ""} then {
  912.         insertOption $option
  913.         return 1
  914.     }
  915.     return 0
  916. }
  917. proc getOption {} {
  918.     catch {prompt "Choose an option:" "11pt" "" "10pt" "11pt" "12pt" "(-" ¥
  919.             "letterpaper" "legalpaper" "executivepaper" "a4paper" "a5paper" ¥
  920.             "b5paper" "(-" "landscape" "(-" "final" "draft" "(-" ¥
  921.             "oneside" "twoside" "(-" "openright" "openany" "(-" ¥
  922.             "onecolumn" "twocolumn" "(-" "notitlepage" "titlepage" ¥
  923.                   "openbib" "(-" "leqno" "(-" "fleqn"} optionName
  924.     if {$optionName != "cancel"} then {
  925.         return $optionName
  926.     } else {
  927.         return ""
  928.     }
  929. }
  930. proc insertOption {option} {
  931.     global TeXmodeVars
  932.     set searchString {¥¥documentclass}
  933.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  934.     if {[llength $searchResult] == 0} then {
  935.         if { $TeXmodeVars(searchNoisily) } {beep}
  936.         message "can¥'t find ¥¥documentclass"
  937.     } else {
  938.         set nextCharPos [lindex $searchResult 1]
  939.         goto $nextCharPos
  940.         set nextChar [lookAt $nextCharPos]
  941.         if {$nextChar == "¥["} then {
  942.             forwardChar
  943.             insertText $option
  944.             if {[lookAt [getPos]] != "¥]"} then {
  945.                 insertText ","
  946.             }
  947.         } elseif {$nextChar == "¥{"} then {
  948.             insertText "¥[$option¥]"
  949.         } else {
  950.             alertnote "unrecognizable ¥¥documentclass statement"
  951.         }
  952.     }
  953. }
  954.  
  955. proc insertPackage {package} {
  956.     global TeXmodeVars
  957.     # Check to see if $package is already loaded:
  958.     if { $package != "" } then {
  959. #         append searchString {¥¥usepackage¥{.*} $package {.*¥}}
  960.         append searchString {^[^%]*¥¥usepackage¥{.*} $package {.*¥}}
  961.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  962.         if {[llength $searchResult] != 0} then {
  963.             if { $TeXmodeVars(searchNoisily) } {beep}
  964.             message "$package package already loaded"
  965.             return
  966.         }
  967.     }
  968.     # Newlines are allowed in the arguments of ¥documentclass:
  969.     set searchString {¥¥documentclass(¥[[^][]*¥])?{[^{}]*}}
  970.     # Search for ¥documentclass command:
  971.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  972.     if {[llength $searchResult] == 0} then {
  973.         if { $TeXmodeVars(searchNoisily) } {beep}
  974.         message "can't find ¥¥documentclass"
  975.     } else {
  976.         pushMark
  977.         goto [lindex $searchResult 1]
  978.         set txt "¥r¥¥usepackage¥{$package¥}"
  979.         insertText $txt
  980.         backwardChar
  981.         message "Press <Ctl .> to return to previous position"
  982.     }
  983. }
  984.  
  985. proc filecontents {} {
  986.     global searchNoisily
  987.     set searchString {¥¥documentclass}
  988.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  989.     if {[llength $searchResult] == 0} then {
  990.         if {$searchNoisily} {beep}
  991.         message "can¥'t find ¥¥documentclass"
  992.         return
  993.     } else {
  994.         set prompt "File to be included:"
  995.         if {[catch {getfile $prompt} path]} then {
  996.             return
  997.         } else {
  998.             replaceText 0 0 [buildFilecontents $path]
  999.             goto 0
  1000.             message "file included"
  1001.         }
  1002.     }
  1003. }
  1004. proc filecontentsAll {} {
  1005.     global searchNoisily
  1006.     watchCursor
  1007.     message "locating all input filesノ"
  1008.     set currentWin [lindex [winNames -f] 0]
  1009.     # Is the current window part of TeX fileset?
  1010.     set fset [isWindowInFileset $currentWin "tex"]
  1011.     if { $fset == "" } {
  1012.         set searchString {¥¥documentclass}
  1013.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1014.         if {[llength $searchResult] == 0} then {
  1015.             if {$searchNoisily} {beep}
  1016.             message "can¥'t find ¥¥documentclass"
  1017.             return
  1018.         } else {
  1019.             set text [getText 0 [maxPos]]
  1020.         }
  1021.     } else {
  1022.         # Will not handle a base file that is open and dirty:
  1023.         set text [buildFilecontents [texFilesetBaseName $fset]]
  1024.     }
  1025.     set currentDir [file dirname $currentWin]
  1026.     set newText [texResolveAll $text $currentDir]
  1027.     if { [string length $text] == [string length $newText] } then {
  1028.         beep
  1029.         message "no files to include"
  1030.     } else {
  1031.         replaceText 0 [maxPos] $newText
  1032.         goto 0
  1033.         message "all files included"
  1034.     }
  1035. }
  1036. # Takes a LaTeX document string and a path as input, and returns
  1037. # a modified document string with all filecontents environments
  1038. # prepended.
  1039. proc texResolveAll {latexDoc currentDir} {
  1040.     global TeXmodeVars
  1041.     set pairs [list ¥
  1042.                 {{¥¥documentclass} {.cls}} {{¥¥LoadClass} {.cls}} ¥
  1043.                 {{¥¥include} {.tex}} ¥
  1044.                 {{¥¥usepackage} {.sty}} {{¥¥RequirePackage} {.sty}} ¥
  1045.                 {{¥¥input} {}} ¥
  1046.                 {{¥¥bibliography} {.bib}} {{¥¥bibliographystyle} {.bst}} ¥
  1047.               ]
  1048.     foreach macro $TeXmodeVars(boxMacroNames) {
  1049.         regsub {¥*} $macro {¥¥*} macro
  1050.         lappend pairs [list ¥¥¥¥$macro {}]
  1051.     }
  1052.     foreach pair $pairs {
  1053.         set cmd [car $pair]
  1054.         set ext [cadr $pair]
  1055.         set searchString $cmd
  1056.         append searchString {(¥[[^][]*¥])?{([^{}]*)}}
  1057.         set searchText $latexDoc
  1058.         while { [regexp -indices $searchString $searchText mtch dummy theArgs] } {
  1059.             set begPos [lindex $theArgs 0]
  1060.             set endPos [lindex $theArgs 1]
  1061.             set args [string range $searchText $begPos $endPos]
  1062.             foreach arg [split $args ,] {
  1063.                 if { $cmd == {¥¥input} && ![string length [file extension $arg]] } {
  1064.                     set ext {.tex}
  1065.                 }
  1066.                 set files [glob -nocomplain $currentDir:$arg*]
  1067.                 set filename "$currentDir:$arg$ext"
  1068.                 if { [lsearch -exact $files $filename] > -1 } {
  1069.                     set tempDoc $latexDoc
  1070.                     set latexDoc [buildFilecontents $filename]
  1071.                     append latexDoc $tempDoc
  1072.                 }
  1073.             }
  1074.             set searchText [string range $searchText [expr $endPos + 2] end]
  1075.         }
  1076.     }
  1077.     return $latexDoc
  1078. }
  1079. # Takes a filename as input and returns a filecontents environment 
  1080. # based on the contents of that file.  If a second argument is given,
  1081. # use that as the argument of the filecontents environment instead
  1082. # of the original filename.
  1083. proc buildFilecontents {filename {newFilename {}}} {
  1084.     set text [readFile $filename]
  1085.     # Fix end-of-line characters:
  1086.     regsub -all "¥xa" $text "¥xd" text
  1087.     set envName "filecontents"
  1088.     if { $newFilename == {} } {
  1089.         set envArg "{[file tail $filename]}"
  1090.     } else {
  1091.         set envArg "{$newFilename}"
  1092.     }
  1093.     return [buildEnvironment $envName $envArg "$text¥r" "¥r¥r"]
  1094. }
  1095.  
  1096. #--------------------------------------------------------------------------
  1097. # Page Layout:
  1098. #--------------------------------------------------------------------------
  1099.  
  1100. proc maketitle {} {
  1101.     global searchNoisily
  1102.     set searchString {¥¥document(class|style)(¥[.*¥])?¥{.*¥}}
  1103.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1104.     if {[llength $searchResult] == 0} then {
  1105.         if {$searchNoisily} {beep}
  1106.         message "can¥'t find ¥¥documentclass or ¥¥documentstyle"
  1107.     } else {
  1108.         set searchPos [lindex $searchResult 1]
  1109.         set searchString {¥¥begin¥{document¥}}
  1110.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString $searchPos]
  1111.         if {[llength $searchResult] == 0} then {
  1112.             if {$searchNoisily} {beep}
  1113.             message "can¥'t find ¥¥begin¥{document¥}"
  1114.         } else {
  1115.             goto [lindex $searchResult 1]
  1116.             set currentPos [getPos]
  1117.             set txt "¥r¥r% Definition of title page:"
  1118.             append txt "¥r¥¥title¥{"
  1119.             append txt "¥r¥t・¥r¥}"
  1120.             append txt "¥r¥¥author¥{"
  1121.             append txt "¥r¥t・¥t% insert author(s) here"
  1122.             append txt "¥r¥}"
  1123.             append txt "¥r¥¥date¥{・¥}¥t% optional"
  1124.             append txt "¥r¥r¥¥maketitle"
  1125.             insertText $txt
  1126.             goto $currentPos
  1127.             nextTabStop
  1128.             message "insert title"
  1129.         }
  1130.     }
  1131. }
  1132. proc abstract {} { doWrapEnvironment "abstract" }
  1133. proc titlepage {} { doWrapEnvironment "titlepage" }
  1134. proc getPagestyle {} {
  1135.     catch {prompt "Choose a pagestyle:" "plain" "" "plain" "empty" ¥
  1136.                   "headings" "myheadings"} pagestyleName
  1137.     if {$pagestyleName != "cancel"} then {
  1138.         return $pagestyleName
  1139.     } else {
  1140.         return ""
  1141.     }
  1142. }
  1143. proc pagestyle {} {
  1144.     set pagestyleName [getPagestyle]
  1145.     if {$pagestyleName != ""} then {
  1146.         openingCarriageReturn
  1147.         insertObject "¥¥pagestyle¥{$pagestyleName¥}"
  1148.         closingCarriageReturn
  1149.     }
  1150. }
  1151. proc thispagestyle {} {
  1152.     set pagestyleName [getPagestyle]
  1153.     if {$pagestyleName != ""} then {
  1154.         openingCarriageReturn
  1155.         insertObject "¥¥thispagestyle¥{$pagestyleName¥}"
  1156.         closingCarriageReturn
  1157.     }
  1158. }
  1159. proc getPagenumberingStyle {} {
  1160.     catch {prompt "Choose a pagenumbering style:" "arabic" "" "arabic" ¥
  1161.                   "roman" "Roman" "alph" "Alph"} pagenumberingStyle
  1162.     if {$pagenumberingStyle != "cancel"} then {
  1163.         return $pagenumberingStyle
  1164.     } else {
  1165.         return ""
  1166.     }
  1167. }
  1168. proc pagenumbering {} {
  1169.     set pagenumberingStyle [getPagenumberingStyle]
  1170.     if {$pagenumberingStyle != ""} then {
  1171.         openingCarriageReturn
  1172.         insertObject "¥¥pagenumbering¥{$pagenumberingStyle¥}"
  1173.         closingCarriageReturn
  1174.     }
  1175. }
  1176. proc twocolumn {} {
  1177.     openingCarriageReturn
  1178.     insertObject "¥¥twocolumn"
  1179.     closingCarriageReturn
  1180. }
  1181. proc onecolumn {} {
  1182.     openingCarriageReturn
  1183.     insertObject "¥¥onecolumn"
  1184.     closingCarriageReturn
  1185. }
  1186.  
  1187. #--------------------------------------------------------------------------
  1188. # Sectioning:
  1189. #--------------------------------------------------------------------------
  1190.  
  1191. proc part {} {
  1192.     if {[wrapObject "¥¥part{" "}・"]} then {
  1193.         message "don't forget the label"
  1194.     } else {
  1195.         message "type the part name and don't forget the label"
  1196.     }
  1197. }
  1198. proc chapter {} {
  1199.     if {[wrapObject "¥¥chapter{" "}・"]} then {
  1200.         message "don't forget the label"
  1201.     } else {
  1202.         message "type the chapter name and don't forget the label"
  1203.     }
  1204. }
  1205. proc section {} {
  1206.     if {[wrapObject "¥¥section{" "}・"]} then {
  1207.         message "don't forget the label"
  1208.     } else {
  1209.         message "type the section name and don't forget the label"
  1210.     }
  1211. }
  1212. proc subsection {} {
  1213.     if {[wrapObject "¥¥subsection{" "}・"]} then {
  1214.         message "don't forget the label"
  1215.     } else {
  1216.         message "type the subsection name and don't forget the label"
  1217.     }
  1218. }
  1219. proc subsubsection {} {
  1220.     if {[wrapObject "¥¥subsubsection{" "}・"]} then {
  1221.         message "don't forget the label"
  1222.     } else {
  1223.         message "type the subsubsection name and don't forget the label"
  1224.     }
  1225. }
  1226. proc paragraph {} {
  1227.     if {[wrapObject "¥¥paragraph{" "}・"]} then {
  1228.         message "don't forget the label"
  1229.     } else {
  1230.         message "type the paragraph name and don't forget the label"
  1231.     }
  1232. }
  1233. proc subparagraph {} {
  1234.     if {[wrapObject "¥¥subparagraph{" "}・"]} then {
  1235.         message "don't forget the label"
  1236.     } else {
  1237.         message "type the subparagraph name and don't forget the label"
  1238.     }
  1239. }
  1240. proc appendix {} {insertObject "¥¥appendix"}
  1241.  
  1242. #--------------------------------------------------------------------------
  1243. # Text Style:
  1244. #--------------------------------------------------------------------------
  1245.  
  1246. proc emph {} {
  1247.     if {[wrapObject "¥¥emph{" "}・"]} then {
  1248.         message "selected text has been emphasized"
  1249.     } else {
  1250.         message "enter text to be emphasized"
  1251.     }
  1252. }
  1253. proc textup {} {
  1254.     if {[wrapObject "¥¥textup{" "}・"]} then {
  1255.         message "selected text has upright shape"
  1256.     } else {
  1257.         message "enter text to have upright shape"
  1258.     }
  1259. }
  1260. proc textit {} {
  1261.     if {[wrapObject "¥¥textit{" "}・"]} then {
  1262.         message "selected text has italic shape"
  1263.     } else {
  1264.         message "enter text to have italic shape"
  1265.     }
  1266. }
  1267. proc textsl {} {
  1268.     if {[wrapObject "¥¥textsl{" "}・"]} then {
  1269.         message "selected text has slanted shape"
  1270.     } else {
  1271.         message "enter text to have slanted shape"
  1272.     }
  1273. }
  1274. proc textsc {} {
  1275.     if {[wrapObject "¥¥textsc{" "}・"]} then {
  1276.         message "selected text has small caps shape"
  1277.     } else {
  1278.         message "enter text to have small caps shape"
  1279.     }
  1280. }
  1281. proc textmd {} {
  1282.     if {[wrapObject "¥¥textmd{" "}・"]} then {
  1283.         message "selected text has been set in medium series"
  1284.     } else {
  1285.         message "enter text to be set in medium series"
  1286.     }
  1287. }
  1288. proc textbf {} {
  1289.     if {[wrapObject "¥¥textbf{" "}・"]} then {
  1290.         message "selected text has been set in bold series"
  1291.     } else {
  1292.         message "enter text to be set in bold series"
  1293.     }
  1294. }
  1295. proc textrm {} {
  1296.     if {[wrapObject "¥¥textrm{" "}・"]} then {
  1297.         message "selected text has been set with roman family"
  1298.     } else {
  1299.         message "enter text to be set using roman family"
  1300.     }
  1301. }
  1302. proc textsf {} {
  1303.     if {[wrapObject "¥¥textsf{" "}・"]} then {
  1304.         message "selected text has been set with sans serif family"
  1305.     } else {
  1306.         message "enter text to be set using sans serif family"
  1307.     }
  1308. }
  1309. proc texttt {} {
  1310.     if {[wrapObject "¥¥texttt{" "}・"]} then {
  1311.         message "selected text has been set with typewriter family"
  1312.     } else {
  1313.         message "enter text to be set using typewriter family"
  1314.     }
  1315. }
  1316. proc textnormal {} {
  1317.     if {[wrapObject "¥¥textnormal{" "}・"]} then {
  1318.         message "selected text has been set with normal style"
  1319.     } else {
  1320.         message "enter text to be set using normal style"
  1321.     }
  1322. }
  1323.  
  1324. proc em {} {
  1325.     if {[wrapObject "{¥¥em " "}・"]} then {
  1326.         message "emphasized text set"
  1327.     } else {
  1328.         message "enter text to be emphasized"
  1329.     }
  1330. }
  1331. proc upshape {} {
  1332.     if {[wrapObject "{¥¥upshape " "}・"]} then {
  1333.         message "text set in upright shape"
  1334.     } else {
  1335.         message "enter text to be set in upright shape"
  1336.     }
  1337. }
  1338. proc itshape {} {
  1339.     if {[wrapObject "{¥¥itshape " "}・"]} then {
  1340.         message "text set in italics shape"
  1341.     } else {
  1342.         message "enter text to be set in italics shape"
  1343.     }
  1344. }
  1345. proc slshape {} {
  1346.     if {[wrapObject "{¥¥slshape " "}・"]} then {
  1347.         message "text set in slanted shape"
  1348.     } else {
  1349.         message "enter text to be set in slanted shape"
  1350.     }
  1351. }
  1352. proc scshape {} {
  1353.     if {[wrapObject "{¥¥scshape " "}・"]} then {
  1354.         message "text set in small caps shape"
  1355.     } else {
  1356.         message "enter text to be set in small caps shape"
  1357.     }
  1358. }
  1359. proc mdseries {} {
  1360.     if {[wrapObject "{¥¥mdseries " "}・"]} then {
  1361.         message "text set in medium series"
  1362.     } else {
  1363.         message "enter text to be set in medium series"
  1364.     }
  1365. }
  1366. proc bfseries {} {
  1367.     if {[wrapObject "{¥¥bfseries " "}・"]} then {
  1368.         message "text set in bold series"
  1369.     } else {
  1370.         message "enter text to be set in bold series"
  1371.     }
  1372. }
  1373. proc rmfamily {} {
  1374.     if {[wrapObject "{¥¥rmfamily " "}・"]} then {
  1375.         message "text set in roman family"
  1376.     } else {
  1377.         message "enter text to be set in roman family"
  1378.     }
  1379. }
  1380. proc sffamily {} {
  1381.     if {[wrapObject "{¥¥sffamily " "}・"]} then {
  1382.         message "text set in sans serif family"
  1383.     } else {
  1384.         message "enter text to be set in sans serif family"
  1385.     }
  1386. }
  1387. proc ttfamily {} {
  1388.     if {[wrapObject "{¥¥ttfamily " "}・"]} then {
  1389.         message "text set in typewriter family"
  1390.     } else {
  1391.         message "enter text to be set in typewriter family"
  1392.     }
  1393. }
  1394. proc normalfont {} {
  1395.     if {[wrapObject "{¥¥normalfont " "}・"]} then {
  1396.         message "text set in normal style"
  1397.     } else {
  1398.         message "enter text to be set in normal style"
  1399.     }
  1400. }
  1401.  
  1402. #--------------------------------------------------------------------------
  1403. # Text Size:
  1404. #--------------------------------------------------------------------------
  1405.  
  1406. proc tiny {} {
  1407.     if {[wrapObject "{¥¥tiny " "}・"]} then {
  1408.         message "tiny text set"
  1409.     } else {
  1410.         message "enter tiny text"
  1411.     }
  1412. }
  1413. proc scriptsize {} {
  1414.     if {[wrapObject "{¥¥scriptsize " "}・"]} then {
  1415.         message "scriptsize text set"
  1416.     } else {
  1417.         message "enter scriptsize text"
  1418.     }
  1419. }
  1420. proc footnotesize {} {
  1421.     if {[wrapObject "{¥¥footnotesize " "}・"]} then {
  1422.         message "footnotesize text set"
  1423.     } else {
  1424.         message "enter footnotesize text"
  1425.     }
  1426. }
  1427. proc small {} {
  1428.     if {[wrapObject "{¥¥small " "}・"]} then {
  1429.         message "small text set"
  1430.     } else {
  1431.         message "enter small text"
  1432.     }
  1433. }
  1434. proc normalsize {} {
  1435.     if {[wrapObject "{¥¥normalsize " "}・"]} then {
  1436.         message "normalsize text set"
  1437.     } else {
  1438.         message "enter normalsize text"
  1439.     }
  1440. }
  1441. proc large {} {
  1442.     if {[wrapObject "{¥¥large " "}・"]} then {
  1443.         message "large text set"
  1444.     } else {
  1445.         message "enter large text"
  1446.     }
  1447. }
  1448. proc Large {} {
  1449.     if {[wrapObject "{¥¥Large " "}・"]} then {
  1450.         message "Large text set"
  1451.     } else {
  1452.         message "enter Large text"
  1453.     }
  1454. }
  1455. proc LARGE {} {
  1456.     if {[wrapObject "{¥¥LARGE " "}・"]} then {
  1457.         message "LARGE text set"
  1458.     } else {
  1459.         message "enter LARGE text"
  1460.     }
  1461. }
  1462. proc huge {} {
  1463.     if {[wrapObject "{¥¥huge " "}・"]} then {
  1464.         message "huge text set"
  1465.     } else {
  1466.         message "enter huge text"
  1467.     }
  1468. }
  1469. proc Huge {} {
  1470.     if {[wrapObject "{¥¥Huge " "}・"]} then {
  1471.         message "Huge text set"
  1472.     } else {
  1473.         message "enter Huge text"
  1474.     }
  1475. }
  1476.  
  1477. #--------------------------------------------------------------------------
  1478. # International:
  1479. #--------------------------------------------------------------------------
  1480.  
  1481. proc {˜} {} {
  1482.     if {[wrapObject "¥¥`{" "}・"]} then {
  1483.         message "accent set"
  1484.     } else {
  1485.         message "enter single character"
  1486.     }
  1487. }
  1488. proc {抑 {} {
  1489.     if {[wrapObject "¥¥'{" "}・"]} then {
  1490.         message "accent set"
  1491.     } else {
  1492.         message "enter single character"
  1493.     }
  1494. }
  1495. proc {凩 {} {
  1496.     if {[wrapObject "¥¥^{" "}・"]} then {
  1497.         message "accent set"
  1498.     } else {
  1499.         message "enter single character"
  1500.     }
  1501. }
  1502. proc {嘲 {} {
  1503.     if {[wrapObject "¥¥¥"{" "}・"]} then {
  1504.         message "accent set"
  1505.     } else {
  1506.         message "enter single character"
  1507.     }
  1508. }
  1509. proc {孺 {} {
  1510.     if {[wrapObject "¥¥~{" "}・"]} then {
  1511.         message "accent set"
  1512.     } else {
  1513.         message "enter single character"
  1514.     }
  1515. }
  1516. proc {閤 {} {insertObject "¥¥c¥{c¥}"}
  1517. proc {‚} {} {insertObject "¥¥c¥{C¥}"}
  1518. proc {マ} {} {insertObject "¥¥oe"}
  1519. proc {ホ} {} {insertObject "¥¥OE"}
  1520. proc {セ} {} {insertObject "¥¥ae"}
  1521. proc {ョ} {} {insertObject "¥¥AE"}
  1522. proc {迎 {} {insertObject "¥¥aa"}
  1523. proc {± {} {insertObject "¥¥AA"}
  1524. proc {ソ} {} {insertObject "¥¥o"}
  1525. proc {ッ} {} {insertObject "¥¥O"}
  1526. proc {ァ} {} {insertObject "¥¥ss"}
  1527. proc {タ} {} {insertObject "?`"}
  1528. proc {チ} {} {insertObject "!`"}
  1529.  
  1530. #--------------------------------------------------------------------------
  1531. # Environments:
  1532. #--------------------------------------------------------------------------
  1533.  
  1534. proc enumerate {} {
  1535.     global promptNoisily useStatusBar
  1536.     set envName "enumerate"
  1537.     if {$promptNoisily && $useStatusBar} {beep}
  1538.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1539.     if {$numberItems == "cancel"} then {
  1540.         return
  1541.     } elseif {![isPositiveInteger $numberItems]} then {
  1542.         beep
  1543.         message "invalid input:  unsigned, postive integer required"
  1544.         return
  1545.     }
  1546.     if {$numberItems} then {
  1547.         set body "¥t¥¥item  ・"
  1548.         for {set i 1} {$i < $numberItems} {incr i} {
  1549.             append body "¥r¥r¥t¥¥item  ・"
  1550.         }
  1551.         append body "¥r"
  1552.     } else {
  1553.         set body "¥t・¥r"
  1554.     }
  1555.     if {[insertEnvironment $envName "" $body]} then {
  1556.         nextTabStop
  1557.         message "type first item"
  1558.     }
  1559. }
  1560. proc itemize {} {
  1561.     global promptNoisily useStatusBar
  1562.     set envName "itemize"
  1563.     if {$promptNoisily && $useStatusBar} {beep}
  1564.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1565.     if {$numberItems == "cancel"} then {
  1566.         return
  1567.     } elseif {![isPositiveInteger $numberItems]} then {
  1568.         beep
  1569.         message "invalid input:  unsigned, postive integer required"
  1570.         return
  1571.     }
  1572.     if {$numberItems} then {
  1573.         set body "¥t¥¥item  ・"
  1574.         for {set i 1} {$i < $numberItems} {incr i} {
  1575.             append body "¥r¥r¥t¥¥item  ・"
  1576.         }
  1577.         append body "¥r"
  1578.     } else {
  1579.         set body "¥t・¥r"
  1580.     }
  1581.     if {[insertEnvironment $envName "" $body]} then {
  1582.         nextTabStop
  1583.         message "type first item"
  1584.     }
  1585. }
  1586. proc description {} {
  1587.     global promptNoisily useStatusBar
  1588.     set envName "description"
  1589.     if {$promptNoisily && $useStatusBar} {beep}
  1590.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1591.     if {$numberItems == "cancel"} then {
  1592.         return
  1593.     } elseif {![isPositiveInteger $numberItems]} then {
  1594.         beep
  1595.         message "invalid input:  unsigned, postive integer required"
  1596.         return
  1597.     }
  1598.     if {$numberItems} then {
  1599.         set body "¥t¥¥item¥[・¥]  ・"
  1600.         for {set i 1} {$i < $numberItems} {incr i} {
  1601.             append body "¥r¥r¥t¥¥item¥[・¥]  ・"
  1602.         }
  1603.         append body "¥r"
  1604.     } else {
  1605.         set body "¥t・¥r"
  1606.     }
  1607.     if {[insertEnvironment $envName "" $body]} then {
  1608.         nextTabStop
  1609.         message "type first item label"
  1610.     }
  1611. }
  1612. proc thebibliography {} {
  1613.     global promptNoisily useStatusBar
  1614.     set envName "thebibliography"
  1615.     if {$promptNoisily && $useStatusBar} {beep}
  1616.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1617.     if {$numberItems == "cancel"} then {
  1618.         return
  1619.     } elseif {![isPositiveInteger $numberItems]} then {
  1620.         beep
  1621.         message "invalid input:  unsigned, postive integer required"
  1622.         return
  1623.     }
  1624.     set arg "{9}"
  1625.     if {$numberItems} then {
  1626.         if {$numberItems > 9} then {set arg "{99}"}
  1627.         set body "¥t¥¥bibitem{・}  ・"
  1628.         for {set i 1} {$i < $numberItems} {incr i} {
  1629.             append body "¥r¥r¥t¥¥bibitem{・}  ・"
  1630.         }
  1631.         append body "¥r"
  1632.     } else {
  1633.         set body "¥t・¥r"
  1634.     }
  1635.     if {[insertEnvironment $envName $arg $body]} then {
  1636.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(9)+} [getPos]]
  1637.         eval select $searchResult
  1638.         message "Change the length of the key field?"
  1639.     }
  1640. }
  1641. proc slide {} { doWrapEnvironment "slide" }
  1642. proc overlay {} { doWrapEnvironment "overlay" }
  1643. proc note {} { doWrapEnvironment "note" }
  1644. # proc figure {} {
  1645. #     global TeXmodeVars
  1646. #     set envName "figure"
  1647. #     set envArg "tbp"
  1648. #     set arg "¥[$envArg¥]"
  1649. #     set theIndentation [getIndentation [getPos]]
  1650. #     append arg "¥r$theIndentation¥t¥¥centering"
  1651. #     set body ""
  1652. #     if { $TeXmodeVars(useBoxMacro) } then {
  1653. #         set defaultMacro [car $TeXmodeVars(boxMacroNames)]
  1654. #         if { $defaultMacro == "" } {
  1655. #             append body "¥t・¥r"
  1656. #         } else {
  1657. #             set restOfMacros [cdr $TeXmodeVars(boxMacroNames)]
  1658. #             if { ![llength $restOfMacros] } {
  1659. #                 append body "¥t¥¥$defaultMacro{・}¥r"
  1660. #             } else {
  1661. #                 set cmd [list prompt "Choose a boxMacro:"]
  1662. #                 lappend cmd $defaultMacro "" 
  1663. #                 foreach boxMacroName $TeXmodeVars(boxMacroNames) {
  1664. #                     lappend cmd $boxMacroName
  1665. #                 }
  1666. #                 catch $cmd macro
  1667. #                 if {$macro != "cancel"} then {
  1668. #                     append body "¥t¥¥$macro{・}¥r"
  1669. #                 } else {
  1670. #                     message "operation canceled"
  1671. #                     return
  1672. #                 }
  1673. #             }
  1674. #         }
  1675. #     }
  1676. #     append body "¥t¥¥caption{・}¥r"
  1677. #     append body "¥t¥¥label{・}¥r"
  1678. #     if { $TeXmodeVars(useBoxMacro) } then {
  1679. #         if {![insertEnvironment $envName $arg $body]} then {return}
  1680. #     } else {
  1681. #         wrapEnvironment $envName $arg $body
  1682. #     }
  1683. #     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1684. #     eval select $searchResult
  1685. #     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1686. # }
  1687. proc figure {} {
  1688.     global TeXmodeVars
  1689.     set envName "figure"
  1690.     set envArg "tbp"
  1691.     set arg "¥[$envArg¥]"
  1692.     set theIndentation [getIndentation [getPos]]
  1693.     append arg "¥r$theIndentation¥t¥¥centering"
  1694.     set body ""
  1695.     set macro [car $TeXmodeVars(boxMacroNames)]
  1696.     if { $macro != "" } {
  1697.         set restOfMacros [cdr $TeXmodeVars(boxMacroNames)]
  1698.         if { ![llength $restOfMacros] } {
  1699.             append body "¥t¥¥$macro{・}¥r"
  1700.         } else {
  1701.             set cmd [list prompt "Choose a box macro:"]
  1702.             lappend cmd $macro "" 
  1703.             foreach boxMacroName $TeXmodeVars(boxMacroNames) {
  1704.                 lappend cmd $boxMacroName
  1705.             }
  1706.             catch $cmd macro
  1707.             if {$macro == "cancel"} then {
  1708.                 message "operation canceled"
  1709.                 return
  1710.             } elseif {$macro == ""} then {
  1711.                 # do nothing
  1712.             } else {
  1713.                 append body "¥t¥¥$macro{・}¥r"
  1714.             }
  1715.         }
  1716.     }
  1717.     append body "¥t¥¥caption{・}¥r"
  1718.     append body "¥t¥¥label{・}¥r"
  1719.     if { $macro == "" } then {
  1720.         wrapEnvironment $envName $arg $body
  1721.     } else {
  1722.         if {![insertEnvironment $envName $arg $body]} then {return}
  1723.     }
  1724.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1725.     eval select $searchResult
  1726.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1727. }
  1728. proc table {} {
  1729.     set envName "table"
  1730.     set envArg "tbp"
  1731.     set arg "¥[$envArg¥]"
  1732.     set theIndentation [getIndentation [getPos]]
  1733.     append arg "¥r$theIndentation¥t¥¥centering"
  1734.     # The following statement puts the caption at the top:
  1735.     append arg "¥r$theIndentation¥t¥¥caption{・}"
  1736.     # The following statement puts the caption at the bottom:
  1737. #     set body "¥t¥¥caption{・}¥r"
  1738.     append body "¥t¥¥label{・}¥r"
  1739.     wrapEnvironment $envName $arg $body
  1740.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1741.     eval select $searchResult
  1742.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1743. }
  1744. proc buildRow {jmax} {
  1745.     set txt "・"
  1746.     for {set j 1} {$j < $jmax} {incr j} {
  1747.         append txt " & ・"
  1748.     }
  1749.     return $txt
  1750. }
  1751. proc tabular {} {
  1752.     global promptNoisily useStatusBar
  1753.     set envName "tabular"
  1754.     if {$promptNoisily && $useStatusBar} {beep}
  1755.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1756.     if {$numberRows == "cancel"} then {
  1757.         return
  1758.     } elseif {![isPositiveInteger $numberRows]} then {
  1759.         beep
  1760.         message "invalid input:  unsigned, postive integer required"
  1761.         return
  1762.     }
  1763.     if {$promptNoisily && $useStatusBar} {beep}
  1764.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  1765.     if {$numberCols == "cancel"} then {
  1766.         return
  1767.     } elseif {![isPositiveInteger $numberCols]} then {
  1768.         beep
  1769.         message "invalid input:  unsigned, postive integer required"
  1770.         return
  1771.     }
  1772.     set arg "{|"
  1773.     for {set j 1} {$j <= $numberCols} {incr j} {
  1774.         append arg "c|"
  1775.     }
  1776.     append arg "}"
  1777.     set body "¥t¥¥hline¥r"
  1778.     for {set i 1} {$i <= $numberRows} {incr i} {
  1779.         append body "¥t[buildRow $numberCols]"
  1780.         append body "  ¥¥¥¥¥r¥t¥¥hline¥r"
  1781.     }
  1782.     if {[insertEnvironment $envName $arg $body]} then {
  1783.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(c|¥|)+} [getPos]]
  1784.         select [lindex $searchResult 0] [lindex $searchResult 1]
  1785.         message "Modify this argument?"
  1786.     }
  1787. }
  1788. proc verbatim {} { doWrapEnvironment "verbatim" }
  1789. proc quote {} { doWrapEnvironment "quote" }
  1790. proc quotation {} { doWrapEnvironment "quotation" }
  1791. proc verse {} { doWrapEnvironment "verse" }
  1792. proc flushleft {} { doWrapEnvironment "flushleft" }
  1793. proc center {} { doWrapEnvironment "center" }
  1794. proc flushright {} { doWrapEnvironment "flushright" }
  1795. proc general {} {
  1796.     catch {prompt "What environment?" ""} environmentName
  1797.     if {$environmentName != "cancel"} {
  1798.         doWrapEnvironment "$environmentName"
  1799.     }
  1800. }
  1801.  
  1802. #--------------------------------------------------------------------------
  1803. # Boxes:
  1804. #--------------------------------------------------------------------------
  1805.  
  1806. proc mbox {} {
  1807.     if {[wrapObject "¥¥mbox{" "}・"]} then {
  1808.         message "mbox set"
  1809.     } else {
  1810.         message "enter text"
  1811.     }
  1812. }
  1813. proc makebox {} {
  1814.     if {[wrapObject "¥¥makebox¥[・¥]¥[・¥]{" "}・"]} then {
  1815.         message "makebox set; enter the width and position"
  1816.     } else {
  1817.         message "enter the width and position of the makebox, then the text"
  1818.     }
  1819. }
  1820. proc fbox {} {
  1821.     if {[wrapObject "¥¥fbox{" "}・"]} then {
  1822.         message "fbox set"
  1823.     } else {
  1824.         message "enter text"
  1825.     }
  1826. }
  1827. proc framebox {} {
  1828.     if {[wrapObject "¥¥framebox¥[・¥]¥[・¥]{" "}・"]} then {
  1829.         message "framebox set; enter the width and position"
  1830.     } else {
  1831.         message "enter the width and position of the framebox, then the text"
  1832.     }
  1833. }
  1834. proc newsavebox {} {
  1835.     if {[wrapObject "¥¥newsavebox{" "}・"]} then {
  1836.         message "newsavebox defined"
  1837.     } else {
  1838.         message "enter the command name of the sbox or savebox"
  1839.     }
  1840. }
  1841. proc sbox {} {
  1842.     if {[wrapObject "¥¥sbox{・}{" "}・"]} then {
  1843.         message "sbox set; enter the command name"
  1844.     } else {
  1845.         message "enter the command name of the sbox, then the text"
  1846.     }
  1847. }
  1848. proc savebox {} {
  1849.     if {[wrapObject "¥¥savebox{・}¥[・¥]¥[・¥]{" "}・"]} then {
  1850.         message "savebox set; enter the command name"
  1851.     } else {
  1852.         message "enter the command name of the savebox"
  1853.     }
  1854. }
  1855. proc usebox {} {
  1856.     if {[wrapObject "¥¥usebox{" "}・"]} then {
  1857.         message "usebox declared"
  1858.     } else {
  1859.         message "enter the command name of the sbox or savebox"
  1860.     }
  1861. }
  1862. proc raisebox {} {
  1863.     if {[wrapObject "¥¥raisebox{・}¥[・¥]¥[・¥]{" "}・"]} then {
  1864.         message "raisebox set; enter the displacement"
  1865.     } else {
  1866.         message "enter the displacement of the raisebox"
  1867.     }
  1868. }
  1869. proc parbox {} {
  1870.     if {[wrapObject "¥¥parbox¥[・¥]¥{・¥}{" "}・"]} then {
  1871.         message "parbox set; enter the position and width"
  1872.     } else {
  1873.         message "enter the position ¥[b|c|t¥] and width of the parbox, then the text"
  1874.     }
  1875. }
  1876. proc minipage {} {
  1877.     set arg "¥[・¥]{・}"
  1878.     wrapEnvironment "minipage" $arg ""
  1879.     nextTabStop
  1880.     message "enter the position ¥[b|c|t¥] of the minipage, then the width"
  1881. }
  1882. proc rule {} {
  1883.     insertObject "¥¥rule¥[・¥]¥{・¥}{・}・"
  1884.     nthTabStop -4
  1885.     message "enter the displacement of the rule, then width and height"
  1886. }
  1887.  
  1888. #--------------------------------------------------------------------------
  1889. # Misc:
  1890. #--------------------------------------------------------------------------
  1891.  
  1892. proc verb {} {
  1893.     if {[wrapObject "¥¥verb|" "|・"]} then {
  1894.         message "verbatim text set"
  1895.     } else {
  1896.         message "enter verbatim text"
  1897.     }
  1898. }
  1899. proc footnote {} {
  1900.     if {[wrapObject "¥¥footnote{" "}・"]} then {
  1901.         message "footnote set"
  1902.     } else {
  1903.         message "enter footnote"
  1904.     }
  1905. }
  1906. proc marginalNote {} {
  1907.     if {[wrapObject "¥¥marginpar{" "}・"]} then {
  1908.         message "marginal note set"
  1909.     } else {
  1910.         message "enter marginal note"
  1911.     }
  1912. }
  1913.  
  1914. proc label {} {
  1915.     if {[wrapObject "¥¥label{" "}・"]} then {
  1916.         message "label defined"
  1917.     } else {
  1918.         message "enter label"
  1919.     }
  1920. }
  1921. proc ref {} { 
  1922.     TeXRefCompletion "ref"
  1923. }
  1924. proc pageref {} { 
  1925.     TeXRefCompletion "pageref"
  1926. }
  1927. proc cite {} {
  1928.     if {[wrapObject "¥¥cite{" "}・"]} then {
  1929.         message "citation made"
  1930.     } else {
  1931.         message "enter citation key"
  1932.     }
  1933. }
  1934. proc nocite {} {
  1935.     if {[wrapObject "¥¥nocite{" "}・"]} then {
  1936.         message "citation added to the list"
  1937.     } else {
  1938.         message "enter citation key"
  1939.     }
  1940. }
  1941.  
  1942. # Insert an ¥item or a ¥bibitem, depending on the context.
  1943. proc insertItem {} {
  1944.     set command [eval getText [searchEnvironment]]
  1945.     set environment [extractCommandArg $command]
  1946.     switch $environment {
  1947.         "itemize" {
  1948.             set text "¥¥item  ・"
  1949.         }
  1950.         "enumerate" {
  1951.             set text "¥¥item  ・"
  1952.         }
  1953.         "description" {
  1954.             set text "¥¥item¥[・¥]  ・"
  1955.         }
  1956.         "thebibliography" {
  1957.             set text "¥¥bibitem{・}  ・"
  1958.         }
  1959.         default {
  1960.             beep
  1961.             message "insertItem: cursor in $environment environment"
  1962.             return
  1963.         }
  1964.     }
  1965.     set pos [getPos]
  1966.     # Indentation should mirror that of an existing ¥item
  1967.     # (if it exists)
  1968.     insertText [openingCarriageReturn]$text
  1969.     goto $pos
  1970.     nextTabStop
  1971. }
  1972.  
  1973. proc quotes {} {
  1974.     if {[wrapObject "`" "'・"]} then {
  1975.         message "text quoted"
  1976.     } else {
  1977.         message "enter text"
  1978.     }
  1979. }
  1980. proc dblQuotes {} {
  1981.     if {[wrapObject "``" "''・"]} then {
  1982.         message "text double quoted"
  1983.     } else {
  1984.         message "enter text"
  1985.     }
  1986. }
  1987.  
  1988. proc ldots {} {insertObject "¥¥ldots"}
  1989. proc {en-dash} {} {insertObject "--"}
  1990. proc {em-dash} {} {insertObject "---"}
  1991. proc texLogo {} {insertObject "¥¥TeX"}
  1992. proc latexLogo {} {insertObject "¥¥LaTeX"}
  1993. proc latex2eLogo {} {insertObject "¥¥LaTeXe"}
  1994. proc today {} {insertObject "¥¥today"}
  1995.  
  1996. proc dag {} {insertObject "¥¥dag"}
  1997. proc ddag {} {insertObject "¥¥ddag"}
  1998. proc sectionMark {} {insertObject "¥¥S"}
  1999. proc paragraphMark {} {insertObject "¥¥P"}
  2000. proc copyright {} {insertObject "¥¥copyright"}
  2001. proc pounds {} {insertObject "¥¥pounds"}
  2002.  
  2003.  
  2004. #############################################################################
  2005. # Math Mode Macros
  2006. #
  2007. #############################################################################
  2008.  
  2009. #--------------------------------------------------------------------------
  2010. # Math Modes:
  2011. #--------------------------------------------------------------------------
  2012.  
  2013. proc texMath {} {
  2014.     checkMathMode "texMath" 0
  2015.     if {[wrapObject "$" "$・"]} then {
  2016.         message "formula set"
  2017.     } else {
  2018.         message "enter formula"
  2019.     }
  2020. }
  2021. proc texDisplaymath {} {
  2022.     checkMathMode "texDisplaymath" 0
  2023.     if {[wrapObject "$$" "$$・"]} then {
  2024.         message "displayed formula set"
  2025.     } else {
  2026.         message "enter displayed formula"
  2027.     }
  2028. }
  2029. proc latexMath {} {
  2030.     checkMathMode "latexMath" 0
  2031.     if {[wrapObject "¥¥( " " ¥¥)・"]} then {
  2032.         message "formula set"
  2033.     } else {
  2034.         message "enter formula"
  2035.     }
  2036. }
  2037. proc latexDisplaymath {} {
  2038.     checkMathMode "latexDisplaymath" 0
  2039.     if {[wrapObject "¥¥¥[ " " ¥¥¥]・"]} then {
  2040.         message "displayed formula set"
  2041.     } else {
  2042.         message "enter displayed formula"
  2043.     }
  2044. }
  2045.  
  2046. #--------------------------------------------------------------------------
  2047. # Math Style:
  2048. #--------------------------------------------------------------------------
  2049.  
  2050. proc mathit {} {
  2051.     checkMathMode "mathit" 1
  2052.     if {[wrapObject "¥¥mathit{" "}・"]} then {
  2053.         message "selected text is math italic"
  2054.     } else {
  2055.         message "enter text to be math italic"
  2056.     }
  2057. }
  2058. proc mathrm {} {
  2059.     checkMathMode "mathrm" 1
  2060.     if {[wrapObject "¥¥mathrm{" "}・"]} then {
  2061.         message "selected text is math roman"
  2062.     } else {
  2063.         message "enter text to be math roman"
  2064.     }
  2065. }
  2066. proc mathbf {} {
  2067.     checkMathMode "mathbf" 1
  2068.     if {[wrapObject "¥¥mathbf{" "}・"]} then {
  2069.         message "selected text is math bold"
  2070.     } else {
  2071.         message "enter text to be math bold"
  2072.     }
  2073. }
  2074. proc mathsf {} {
  2075.     checkMathMode "mathsf" 1
  2076.     if {[wrapObject "¥¥mathsf{" "}・"]} then {
  2077.         message "selected text is math sans serif"
  2078.     } else {
  2079.         message "enter text to be math sans serif"
  2080.     }
  2081. }
  2082. proc mathtt {} {
  2083.     checkMathMode "mathtt" 1
  2084.     if {[wrapObject "¥¥mathtt{" "}・"]} then {
  2085.         message "selected text is math typewriter"
  2086.     } else {
  2087.         message "enter text to be math typewriter"
  2088.     }
  2089. }
  2090. proc mathcal {} {
  2091.     checkMathMode "mathcal" 1
  2092.     # Allow upper-case arguments only:
  2093.     if {[isSelection] && ![isUppercase]} then {
  2094.         alertnote "argument to ¥¥mathcal must be uppercase"
  2095.         return
  2096.     }
  2097.     if {[wrapObject "¥¥mathcal{" "}・"]} then {
  2098.         message "selected text is calligraphic"
  2099.     } else {
  2100.         message "enter text to be calligraphic (UPPERCASE letters only)"
  2101.     }
  2102. }
  2103. proc displaystyle {} {
  2104.     checkMathMode "displaystyle" 1
  2105.     if {[wrapObject "{¥¥displaystyle " "}・"]} then {
  2106.         message "displaystyle set"
  2107.     } else {
  2108.         message "enter displaystyle text"
  2109.     }
  2110. }
  2111. proc textstyle {} {
  2112.     checkMathMode "textstyle" 1
  2113.     if {[wrapObject "{¥¥textstyle " "}・"]} then {
  2114.         message "textstyle set"
  2115.     } else {
  2116.         message "enter textstyle text"
  2117.     }
  2118. }
  2119. proc scriptstyle {} {
  2120.     checkMathMode "scriptstyle" 1
  2121.     if {[wrapObject "{¥¥scriptstyle " "}・"]} then {
  2122.         message "scriptstyle set"
  2123.     } else {
  2124.         message "enter scriptstyle text"
  2125.     }
  2126. }
  2127. proc scriptscriptstyle {} {
  2128.     checkMathMode "scriptscriptstyle" 1
  2129.     if {[wrapObject "{¥¥scriptscriptstyle " "}・"]} then {
  2130.         message "scriptscriptstyle set"
  2131.     } else {
  2132.         message "enter scriptscriptstyle text"
  2133.     }
  2134. }
  2135.  
  2136. #--------------------------------------------------------------------------
  2137. # Math Environments:
  2138. #--------------------------------------------------------------------------
  2139.  
  2140. proc math {} { checkMathMode "math" 0; doWrapEnvironment "math" }
  2141. proc displaymath {} {
  2142.     checkMathMode "displaymath" 0
  2143.     global TeXmodeVars
  2144.     if { $TeXmodeVars(useBrackets) } {
  2145.         doWrapStructure {¥[} {} {¥]}
  2146.     } else {
  2147.         doWrapEnvironment "displaymath"
  2148.     }
  2149. }
  2150. proc equation {} {
  2151.     checkMathMode "equation" 0
  2152.     set envName "equation"
  2153.     set body "¥t¥¥label{・}¥r"
  2154.     if {[wrapEnvironment $envName "" $body]} then {
  2155.         set msgText "equation wrapped"
  2156.     } else {
  2157.         set msgText "enter equation"
  2158.     }
  2159.     nextTabStop
  2160.     message $msgText
  2161. }
  2162. proc eqnarrayStar {} {
  2163.     global promptNoisily useStatusBar
  2164.     checkMathMode "eqnarrayStar" 0
  2165.     set envName "eqnarray*"
  2166.     if {$promptNoisily && $useStatusBar} {beep}
  2167.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2168.     if {$numberRows == "cancel"} then {
  2169.         return
  2170.     } elseif {![isPositiveInteger $numberRows]} then {
  2171.         beep
  2172.         message "invalid input:  unsigned, postive integer required"
  2173.         return
  2174.     }
  2175.     set row "¥t[buildRow 3]"
  2176.     for {set i 1} {$i < $numberRows} {incr i} {
  2177.         append body $row
  2178.         append body "  ¥¥¥¥¥r"
  2179.     }
  2180.     append body $row
  2181.     append body "¥r"
  2182.     if {[insertEnvironment $envName "" $body]} then {
  2183.         nextTabStop
  2184.         message "type first item"
  2185.     }
  2186. }
  2187. proc eqnarray {} {
  2188.     global promptNoisily useStatusBar
  2189.     checkMathMode "eqnarray" 0
  2190.     set envName "eqnarray"
  2191.     if {$promptNoisily && $useStatusBar} {beep}
  2192.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2193.     if {$numberRows == "cancel"} then {
  2194.         return
  2195.     } elseif {![isPositiveInteger $numberRows]} then {
  2196.         beep
  2197.         message "invalid input:  unsigned, postive integer required"
  2198.         return
  2199.     }
  2200.     set row "¥t[buildRow 3]¥r¥t¥¥label{・}"
  2201.     for {set i 1} {$i < $numberRows} {incr i} {
  2202.         append body $row
  2203.         append body "  ¥¥¥¥¥r"
  2204.     }
  2205.     append body $row
  2206.     append body "¥r"
  2207.     if {[insertEnvironment $envName "" $body]} then {
  2208.         nextTabStop
  2209.         message "type first item"
  2210.     }
  2211. }
  2212. proc myArray {} {
  2213.     global promptNoisily useStatusBar
  2214.     checkMathMode "myArray" 1
  2215.     set envName "array"
  2216.     if {$promptNoisily && $useStatusBar} {beep}
  2217.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2218.     if {$numberRows == "cancel"} then {
  2219.         return
  2220.     } elseif {![isPositiveInteger $numberRows]} then {
  2221.         beep
  2222.         message "invalid input:  unsigned, postive integer required"
  2223.         return
  2224.     }
  2225.     if {$promptNoisily && $useStatusBar} {beep}
  2226.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  2227.     if {$numberCols == "cancel"} then {
  2228.         return
  2229.     } elseif {![isPositiveInteger $numberCols]} then {
  2230.         beep
  2231.         message "invalid input:  unsigned, postive integer required"
  2232.         return
  2233.     }
  2234.     set arg "{"
  2235.     for {set j 1} {$j <= $numberCols} {incr j} {
  2236.         append arg "c"
  2237.     }
  2238.     append arg "}"
  2239.     set row "¥t[buildRow $numberCols]"
  2240.     for {set i 1} {$i < $numberRows} {incr i} {
  2241.         append body $row
  2242.         append body "  ¥¥¥¥¥r"
  2243.     }
  2244.     append body $row
  2245.     append body "¥r"
  2246.     if {[insertEnvironment $envName $arg $body]} then {
  2247.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {c+} [getPos]]
  2248.         select [lindex $searchResult 0] [lindex $searchResult 1]
  2249.         message "Modify this argument?"
  2250.     }
  2251. }
  2252.  
  2253. #--------------------------------------------------------------------------
  2254. # Formulas:
  2255. #--------------------------------------------------------------------------
  2256.  
  2257. proc subscript {} {
  2258.     checkMathMode "subscript" 1
  2259.     if {[wrapObject "_{" "}・"]} then {
  2260.         message "subscript set"
  2261.     } else {
  2262.         message "enter subscript"
  2263.     }
  2264. }
  2265. proc superscript {} {
  2266.     checkMathMode "superscript" 1
  2267.     if {[wrapObject "^{" "}・"]} then {
  2268.         message "superscript set"
  2269.     } else {
  2270.         message "enter superscript"
  2271.     }
  2272. }
  2273. proc fraction {} {
  2274.     checkMathMode "fraction" 1
  2275.     set currentPos [getPos]
  2276.     if {[isSelection]} then {
  2277.         set selection [getSelect]
  2278.         set args [split $selection /]
  2279.         set len [llength $args]
  2280.         deleteText $currentPos [selEnd]
  2281.         if {$len == 1} then {
  2282.             insertObject "¥¥frac{$selection}{・}・"
  2283.             goto $currentPos
  2284.             nextTabStop
  2285.             message "enter denominator"
  2286.         } else {
  2287.             set firstArg [lindex $args 0]
  2288.             set restArgs [lrange $args 1 [expr $len-1]]
  2289.             insertObject "¥¥frac{$firstArg}{[join $restArgs /]}"
  2290.             if {$len > 2} {message "beware of multiple /"}
  2291.         }
  2292.     } else {
  2293.         insertObject "¥¥frac{・}{・}・"
  2294.         goto $currentPos
  2295.         nextTabStop
  2296.         message "enter numerator"
  2297.     }
  2298. }
  2299. proc squareRoot {} {
  2300.     checkMathMode "squareRoot" 1
  2301.     if {[wrapObject "¥¥sqrt{" "}・"]} then {
  2302.         message "square root set"
  2303.     } else {
  2304.         message "enter formula"
  2305.     }
  2306. }
  2307. proc nthRoot {} {
  2308.     checkMathMode "nthRoot" 1
  2309.     if {[wrapObject "¥¥sqrt¥[・¥]{" "}・"]} then {
  2310.         message "enter root"
  2311.     } else {
  2312.         message "enter root, then formula"
  2313.     }
  2314. }
  2315. proc oneParameter {} {
  2316.     checkMathMode "oneParameter" 1
  2317.     if {[wrapObject "¥¥・{" "}・"]} then {
  2318.         message "enter command name"
  2319.     } else {
  2320.         message "enter command name, press <Tab>, enter argument"
  2321.     }
  2322. }
  2323. proc twoParameters {} {
  2324.     checkMathMode "twoParameters" 1
  2325.     if {[wrapObject "¥¥・{" "}{・}・"]} then {
  2326.         message "enter command name"
  2327.     } else {
  2328.         message "enter command name, press <Tab>, enter argument, etc."
  2329.     }
  2330. }
  2331.  
  2332. #--------------------------------------------------------------------------
  2333. # Greek:
  2334. #--------------------------------------------------------------------------
  2335.  
  2336. proc alpha {} {checkMathMode "alpha" 1; insertObject "¥¥alpha"}
  2337. proc beta {} {checkMathMode "beta" 1; insertObject "¥¥beta"}
  2338. proc gamma {} {checkMathMode "gamma" 1; insertObject "¥¥gamma"}
  2339. proc delta {} {checkMathMode "delta" 1; insertObject "¥¥delta"}
  2340. proc epsilon {} {checkMathMode "epsilon" 1; insertObject "¥¥epsilon"}
  2341. proc zeta {} {checkMathMode "zeta" 1; insertObject "¥¥zeta"}
  2342. proc eta {} {checkMathMode "eta" 1; insertObject "¥¥eta"}
  2343. proc theta {} {checkMathMode "theta" 1; insertObject "¥¥theta"}
  2344. proc iota {} {checkMathMode "iota" 1; insertObject "¥¥iota"}
  2345. proc kappa {} {checkMathMode "kappa" 1; insertObject "¥¥kappa"}
  2346. proc lambda {} {checkMathMode "lambda" 1; insertObject "¥¥lambda"}
  2347. proc mu {} {checkMathMode "mu" 1; insertObject "¥¥mu"}
  2348. proc nu {} {checkMathMode "nu" 1; insertObject "¥¥nu"}
  2349. proc xi {} {checkMathMode "xi" 1; insertObject "¥¥xi"}
  2350. proc omicron {} {checkMathMode "omicron" 1; insertObject "o"}
  2351. proc pi {} {checkMathMode "pi" 1; insertObject "¥¥pi"}
  2352. proc rho {} {checkMathMode "rho" 1; insertObject "¥¥rho"}
  2353. proc sigma {} {checkMathMode "sigma" 1; insertObject "¥¥sigma"}
  2354. proc tau {} {checkMathMode "tau" 1; insertObject "¥¥tau"}
  2355. proc upsilon {} {checkMathMode "upsilon" 1; insertObject "¥¥upsilon"}
  2356. proc phi {} {checkMathMode "phi" 1; insertObject "¥¥phi"}
  2357. proc chi {} {checkMathMode "chi" 1; insertObject "¥¥chi"}
  2358. proc psi {} {checkMathMode "psi" 1; insertObject "¥¥psi"}
  2359. proc omega {} {checkMathMode "omega" 1; insertObject "¥¥omega"}
  2360.  
  2361. proc Gamma {} {checkMathMode "Gamma" 1; insertObject "¥¥Gamma"}
  2362. proc Delta {} {checkMathMode "Delta" 1; insertObject "¥¥Delta"}
  2363. proc Theta {} {checkMathMode "Theta" 1; insertObject "¥¥Theta"}
  2364. proc Lambda {} {checkMathMode "Lambda" 1; insertObject "¥¥Lambda"}
  2365. proc Xi {} {checkMathMode "Xi" 1; insertObject "¥¥Xi"}
  2366. proc Pi {} {checkMathMode "Pi" 1; insertObject "¥¥Pi"}
  2367. proc Sigma {} {checkMathMode "Sigma" 1; insertObject "¥¥Sigma"}
  2368. proc Upsilon {} {checkMathMode "Upsilon" 1; insertObject "¥¥Upsilon"}
  2369. proc Phi {} {checkMathMode "Phi" 1; insertObject "¥¥Phi"}
  2370. proc Psi {} {checkMathMode "Psi" 1; insertObject "¥¥Psi"}
  2371. proc Omega {} {checkMathMode "Omega" 1; insertObject "¥¥Omega"}
  2372.  
  2373. proc varepsilon {} {checkMathMode "varepsilon" 1; insertObject "¥¥varepsilon"}
  2374. proc vartheta {} {checkMathMode "vartheta" 1; insertObject "¥¥vartheta"}
  2375. proc varpi {} {checkMathMode "varpi" 1; insertObject "¥¥varpi"}
  2376. proc varrho {} {checkMathMode "varrho" 1; insertObject "¥¥varrho"}
  2377. proc varsigma {} {checkMathMode "varsigma" 1; insertObject "¥¥varsigma"}
  2378. proc varphi {} {checkMathMode "varphi" 1; insertObject "¥¥varphi"}
  2379.  
  2380. #--------------------------------------------------------------------------
  2381. # Binary Ops:
  2382. #--------------------------------------------------------------------------
  2383.  
  2384. proc pm {} {checkMathMode "pm" 1; insertObject "¥¥pm"}
  2385. proc mp {} {checkMathMode "mp" 1; insertObject "¥¥mp"}
  2386. proc times {} {checkMathMode "times" 1; insertObject "¥¥times"}
  2387. proc div {} {checkMathMode "div" 1; insertObject "¥¥div"}
  2388. proc ast {} {checkMathMode "ast" 1; insertObject "¥¥ast"}
  2389. proc star {} {checkMathMode "star" 1; insertObject "¥¥star"}
  2390. proc circ {} {checkMathMode "circ" 1; insertObject "¥¥circ"}
  2391. proc bullet {} {checkMathMode "bullet" 1; insertObject "¥¥bullet"}
  2392. proc cdot {} {checkMathMode "cdot" 1; insertObject "¥¥cdot"}
  2393. proc cap {} {checkMathMode "cap" 1; insertObject "¥¥cap"}
  2394. proc cup {} {checkMathMode "cup" 1; insertObject "¥¥cup"}
  2395. proc uplus {} {checkMathMode "uplus" 1; insertObject "¥¥uplus"}
  2396. proc sqcap {} {checkMathMode "sqcap" 1; insertObject "¥¥sqcap"}
  2397. proc sqcup {} {checkMathMode "sqcup" 1; insertObject "¥¥sqcup"}
  2398. proc vee {} {checkMathMode "vee" 1; insertObject "¥¥vee"}
  2399. proc wedge {} {checkMathMode "wedge" 1; insertObject "¥¥wedge"}
  2400. proc setminus {} {checkMathMode "setminus" 1; insertObject "¥¥setminus"}
  2401. proc wr {} {checkMathMode "wr" 1; insertObject "¥¥wr"}
  2402. proc diamond {} {checkMathMode "diamond" 1; insertObject "¥¥diamond"}
  2403. proc bigtriangleup {} {
  2404.     checkMathMode "bigtriangleup" 1; insertObject "¥¥bigtriangleup"
  2405. }
  2406. proc bigtriangledown {} {
  2407.     checkMathMode "bigtriangledown" 1; insertObject "¥¥bigtriangledown"
  2408. }
  2409. proc triangleleft {} {
  2410.     checkMathMode "triangleleft" 1; insertObject "¥¥triangleleft"
  2411. }
  2412. proc triangleright {} {
  2413.     checkMathMode "triangleright" 1; insertObject "¥¥triangleright"
  2414. }
  2415. proc lhd {} {
  2416.     if {[isSymbolPackageLoaded]} then {
  2417.         checkMathMode "lhd" 1; insertObject "¥¥lhd"
  2418.     }
  2419. }
  2420. proc rhd {} {
  2421.     if {[isSymbolPackageLoaded]} then {
  2422.         checkMathMode "rhd" 1; insertObject "¥¥rhd"
  2423.     }
  2424. }
  2425. proc unlhd {} {
  2426.     if {[isSymbolPackageLoaded]} then {
  2427.         checkMathMode "unlhd" 1; insertObject "¥¥unlhd"
  2428.     }
  2429. }
  2430. proc unrhd {} {
  2431.     if {[isSymbolPackageLoaded]} then {
  2432.         checkMathMode "unrhd" 1; insertObject "¥¥unrhd"
  2433.     }
  2434. }
  2435. proc oplus {} {checkMathMode "oplus" 1; insertObject "¥¥oplus"}
  2436. proc ominus {} {checkMathMode "ominus" 1; insertObject "¥¥ominus"}
  2437. proc otimes {} {checkMathMode "otimes" 1; insertObject "¥¥otimes"}
  2438. proc oslash {} {checkMathMode "oslash" 1; insertObject "¥¥oslash"}
  2439. proc odot {} {checkMathMode "odot" 1; insertObject "¥¥odot"}
  2440. proc bigcirc {} {checkMathMode "bigcirc" 1; insertObject "¥¥bigcirc"}
  2441. proc dagger {} {checkMathMode "dagger" 1; insertObject "¥¥dagger"}
  2442. proc ddagger {} {checkMathMode "ddagger" 1; insertObject "¥¥ddagger"}
  2443. proc amalg {} {checkMathMode "amalg" 1; insertObject "¥¥amalg"}
  2444.  
  2445. #--------------------------------------------------------------------------
  2446. # Relations:
  2447. #--------------------------------------------------------------------------
  2448.  
  2449. proc leq {} {checkMathMode "leq" 1; insertObject "¥¥leq"}
  2450. proc prec {} {checkMathMode "prec" 1; insertObject "¥¥prec"}
  2451. proc preceq {} {checkMathMode "preceq" 1; insertObject "¥¥preceq"}
  2452. proc myLl {} {checkMathMode "myLl" 1; insertObject "¥¥ll"}
  2453. proc subset {} {checkMathMode "subset" 1; insertObject "¥¥subset"}
  2454. proc subseteq {} {checkMathMode "subseteq" 1; insertObject "¥¥subseteq"}
  2455. proc sqsubset {} {
  2456.     if {[isSymbolPackageLoaded]} then {
  2457.         checkMathMode "sqsubset" 1; insertObject "¥¥sqsubset"
  2458.     }
  2459. }
  2460. proc sqsubseteq {} {checkMathMode "sqsubseteq" 1; insertObject "¥¥sqsubseteq"}
  2461. proc in {} {checkMathMode "in" 1; insertObject "¥¥in"}
  2462. proc vdash {} {checkMathMode "vdash" 1; insertObject "¥¥vdash"}
  2463.  
  2464. proc geq {} {checkMathMode "geq" 1; insertObject "¥¥geq"}
  2465. proc succ {} {checkMathMode "succ" 1; insertObject "¥¥succ"}
  2466. proc succeq {} {checkMathMode "succeq" 1; insertObject "¥¥succeq"}
  2467. proc gg {} {checkMathMode "gg" 1; insertObject "¥¥gg"}
  2468. proc supset {} {checkMathMode "supset" 1; insertObject "¥¥supset"}
  2469. proc supseteq {} {checkMathMode "supseteq" 1; insertObject "¥¥supseteq"}
  2470. proc sqsupset {} {
  2471.     if {[isSymbolPackageLoaded]} then {
  2472.         checkMathMode "sqsupset" 1; insertObject "¥¥sqsupset"
  2473.     }
  2474. }
  2475. proc sqsupseteq {} {checkMathMode "sqsupseteq" 1; insertObject "¥¥sqsupseteq"}
  2476. proc ni {} {checkMathMode "ni" 1; insertObject "¥¥ni"}
  2477. proc dashv {} {checkMathMode "dashv" 1; insertObject "¥¥dashv"}
  2478.  
  2479. proc equiv {} {checkMathMode "equiv" 1; insertObject "¥¥equiv"}
  2480. proc sim {} {checkMathMode "sim" 1; insertObject "¥¥sim"}
  2481. proc simeq {} {checkMathMode "simeq" 1; insertObject "¥¥simeq"}
  2482. proc asymp {} {checkMathMode "asymp" 1; insertObject "¥¥asymp"}
  2483. proc approx {} {checkMathMode "approx" 1; insertObject "¥¥approx"}
  2484. proc cong {} {checkMathMode "cong" 1; insertObject "¥¥cong"}
  2485. proc neq {} {checkMathMode "neq" 1; insertObject "¥¥neq"}
  2486. proc doteq {} {checkMathMode "doteq" 1; insertObject "¥¥doteq"}
  2487. proc propto {} {checkMathMode "propto" 1; insertObject "¥¥propto"}
  2488.  
  2489. proc models {} {checkMathMode "models" 1; insertObject "¥¥models"}
  2490. proc perp {} {checkMathMode "perp" 1; insertObject "¥¥perp"}
  2491. proc mid {} {checkMathMode "mid" 1; insertObject "¥¥mid"}
  2492. proc parallel {} {checkMathMode "parallel" 1; insertObject "¥¥parallel"}
  2493. proc bowtie {} {checkMathMode "bowtie" 1; insertObject "¥¥bowtie"}
  2494. proc myJoin {} {
  2495.     if {[isSymbolPackageLoaded]} then {
  2496.         checkMathMode "myJoin" 1; insertObject "¥¥join"
  2497.     }
  2498. }
  2499. proc smile {} {checkMathMode "smile" 1; insertObject "¥¥smile"}
  2500. proc frown {} {checkMathMode "frown" 1; insertObject "¥¥frown"}
  2501.  
  2502. #--------------------------------------------------------------------------
  2503. # Arrows:
  2504. #--------------------------------------------------------------------------
  2505.  
  2506. proc leftarrow {} {checkMathMode "leftarrow" 1; insertObject "¥¥leftarrow"}
  2507. proc Leftarrow {} {checkMathMode "Leftarrow" 1; insertObject "¥¥Leftarrow"}
  2508. proc rightarrow {} {checkMathMode "rightarrow" 1; insertObject "¥¥rightarrow"}
  2509. proc Rightarrow {} {checkMathMode "Rightarrow" 1; insertObject "¥¥Rightarrow"}
  2510. proc leftrightarrow {} {
  2511.     checkMathMode "leftrightarrow" 1; insertObject "¥¥leftrightarrow"
  2512. }
  2513. proc Leftrightarrow {} {
  2514.     checkMathMode "Leftrightarrow" 1; insertObject "¥¥Leftrightarrow"
  2515. }
  2516. proc mapsto {} {checkMathMode "mapsto" 1; insertObject "¥¥mapsto"}
  2517. proc hookleftarrow {} {
  2518.     checkMathMode "hookleftarrow" 1; insertObject "¥¥hookleftarrow"
  2519. }
  2520. proc leftharpoonup {} {
  2521.     checkMathMode "leftharpoonup" 1; insertObject "¥¥leftharpoonup"
  2522. }
  2523. proc leftharpoondown {} {
  2524.     checkMathMode "leftharpoondown" 1; insertObject "¥¥leftharpoondown"
  2525. }
  2526. proc rightleftharpoons {} {
  2527.     checkMathMode "rightleftharpoons" 1; insertObject "¥¥rightleftharpoons"
  2528. }
  2529.  
  2530. proc longleftarrow {} {
  2531.     checkMathMode "longleftarrow" 1; insertObject "¥¥longleftarrow"
  2532. }
  2533. proc Longleftarrow {} {
  2534.     checkMathMode "Longleftarrow" 1; insertObject "¥¥Longleftarrow"
  2535. }
  2536. proc longrightarrow {} {
  2537.     checkMathMode "longrightarrow" 1; insertObject "¥¥longrightarrow"
  2538. }
  2539. proc Longrightarrow {} {
  2540.     checkMathMode "Longrightarrow" 1; insertObject "¥¥Longrightarrow"
  2541. }
  2542. proc longleftrightarrow {} {
  2543.     checkMathMode "longleftrightarrow" 1; insertObject "¥¥longleftrightarrow"
  2544. }
  2545. proc Longleftrightarrow {} {
  2546.     checkMathMode "Longleftrightarrow" 1; insertObject "¥¥Longleftrightarrow"
  2547. }
  2548. proc longmapsto {} {checkMathMode "longmapsto" 1; insertObject "¥¥longmapsto"}
  2549. proc hookrightarrow {} {
  2550.     checkMathMode "hookrightarrow" 1; insertObject "¥¥hookrightarrow"
  2551. }
  2552. proc rightharpoonup {} {
  2553.     checkMathMode "rightharpoonup" 1; insertObject "¥¥rightharpoonup"
  2554. }
  2555. proc rightharpoondown {} {
  2556.     checkMathMode "rightharpoondown" 1; insertObject "¥¥rightharpoondown"
  2557. }
  2558. proc leadsto {} {
  2559.     if {[isSymbolPackageLoaded]} then {
  2560.         checkMathMode "leadsto" 1; insertObject "¥¥leadsto"
  2561.     }
  2562. }
  2563. proc uparrow {} {checkMathMode "uparrow" 1; insertObject "¥¥uparrow"}
  2564. proc Uparrow {} {checkMathMode "Uparrow" 1; insertObject "¥¥Uparrow"}
  2565. proc downarrow {} {checkMathMode "downarrow" 1; insertObject "¥¥downarrow"}
  2566. proc Downarrow {} {checkMathMode "Downarrow" 1; insertObject "¥¥Downarrow"}
  2567. proc updownarrow {} {checkMathMode "updownarrow" 1; insertObject "¥¥updownarrow"}
  2568. proc Updownarrow {} {checkMathMode "Updownarrow" 1; insertObject "¥¥Updownarrow"}
  2569. proc nearrow {} {checkMathMode "nearrow" 1; insertObject "¥¥nearrow"}
  2570. proc searrow {} {checkMathMode "searrow" 1; insertObject "¥¥searrow"}
  2571. proc swarrow {} {checkMathMode "swarrow" 1; insertObject "¥¥swarrow"}
  2572. proc nwarrow {} {checkMathMode "nwarrow" 1; insertObject "¥¥nwarrow"}
  2573.  
  2574. #--------------------------------------------------------------------------
  2575. # Dots:
  2576. #--------------------------------------------------------------------------
  2577.  
  2578. proc cdots {} {checkMathMode "cdots" 1; insertObject "¥¥cdots"}
  2579. proc vdots {} {checkMathMode "vdots" 1; insertObject "¥¥vdots"}
  2580. proc ddots {} {checkMathMode "ddots" 1; insertObject "¥¥ddots"}
  2581.  
  2582. #--------------------------------------------------------------------------
  2583. # Symbols:
  2584. #--------------------------------------------------------------------------
  2585.  
  2586. proc aleph {} {checkMathMode "aleph" 1; insertObject "¥¥aleph"}
  2587. proc hbar {} {checkMathMode "hbar" 1; insertObject "¥¥hbar"}
  2588. proc imath {} {checkMathMode "imath" 1; insertObject "¥¥imath"}
  2589. proc jmath {} {checkMathMode "jmath" 1; insertObject "¥¥jmath"}
  2590. proc ell {} {checkMathMode "ell" 1; insertObject "¥¥ell"}
  2591. proc wp {} {checkMathMode "wp" 1; insertObject "¥¥wp"}
  2592. proc Re {} {checkMathMode "Re" 1; insertObject "¥¥Re"}
  2593. proc Im {} {checkMathMode "Im" 1; insertObject "¥¥Im"}
  2594. proc mho {} {
  2595.     if {[isSymbolPackageLoaded]} then {
  2596.         checkMathMode "mho" 1; insertObject "¥¥mho"
  2597.     }
  2598. }
  2599. proc prime {} {checkMathMode "prime" 1; insertObject "¥¥prime"}
  2600. proc emptyset {} {checkMathMode "emptyset" 1; insertObject "¥¥emptyset"}
  2601. proc nabla {} {checkMathMode "nabla" 1; insertObject "¥¥nabla"}
  2602. proc surd {} {checkMathMode "surd" 1; insertObject "¥¥surd"}
  2603. proc top {} {checkMathMode "top" 1; insertObject "¥¥top"}
  2604. proc bot {} {checkMathMode "bot" 1; insertObject "¥¥bot"}
  2605. # proc | {} {checkMathMode "|" 1; insertObject "¥¥|"}
  2606. proc angle {} {checkMathMode "angle" 1; insertObject "¥¥angle"}
  2607. proc forall {} {checkMathMode "forall" 1; insertObject "¥¥forall"}
  2608. proc exists {} {checkMathMode "exists" 1; insertObject "¥¥exists"}
  2609. proc neg {} {checkMathMode "neg" 1; insertObject "¥¥neg"}
  2610. proc flat {} {checkMathMode "flat" 1; insertObject "¥¥flat"}
  2611. proc natural {} {checkMathMode "natural" 1; insertObject "¥¥natural"}
  2612. proc sharp {} {checkMathMode "sharp" 1; insertObject "¥¥sharp"}
  2613. proc backslash {} {checkMathMode "backslash" 1; insertObject "¥¥backslash"}
  2614. proc partial {} {checkMathMode "partial" 1; insertObject "¥¥partial"}
  2615. proc infty {} {checkMathMode "infty" 1; insertObject "¥¥infty"}
  2616. proc Box {} {
  2617.     if {[isSymbolPackageLoaded]} then {
  2618.         checkMathMode "Box" 1; insertObject "¥¥Box"
  2619.     }
  2620. }
  2621. proc Diamond {} {
  2622.     if {[isSymbolPackageLoaded]} then {
  2623.         checkMathMode "Diamond" 1; insertObject "¥¥Diamond"
  2624.     }
  2625. }
  2626. proc triangle {} {checkMathMode "triangle" 1; insertObject "¥¥triangle"}
  2627. proc clubsuit {} {checkMathMode "clubsuit" 1; insertObject "¥¥clubsuit"}
  2628. proc diamondsuit {} {checkMathMode "diamondsuit" 1; insertObject "¥¥diamondsuit"}
  2629. proc heartsuit {} {checkMathMode "heartsuit" 1; insertObject "¥¥heartsuit"}
  2630. proc spadesuit {} {checkMathMode "spadesuit" 1; insertObject "¥¥spadesuit"}
  2631.  
  2632. #--------------------------------------------------------------------------
  2633. # Functions:
  2634. #--------------------------------------------------------------------------
  2635.  
  2636. proc arccos {} {checkMathMode "arccos" 1; insertObject "¥¥arccos"}
  2637. proc arcsin {} {checkMathMode "arcsin" 1; insertObject "¥¥arcsin"}
  2638. proc arctan {} {checkMathMode "arctan" 1; insertObject "¥¥arctan"}
  2639. proc arg {} {checkMathMode "arg" 1; insertObject "¥¥arg"}
  2640. proc cos {} {checkMathMode "cos" 1; insertObject "¥¥cos"}
  2641. proc cosh {} {checkMathMode "cosh" 1; insertObject "¥¥cosh"}
  2642. proc cot {} {checkMathMode "cot" 1; insertObject "¥¥cot"}
  2643. proc coth {} {checkMathMode "coth" 1; insertObject "¥¥coth"}
  2644. proc csc {} {checkMathMode "csc" 1; insertObject "¥¥csc"}
  2645. proc deg {} {checkMathMode "deg" 1; insertObject "¥¥deg"}
  2646. proc det {} {checkMathMode "det" 1; insertObject "¥¥det"}
  2647. proc dim {} {checkMathMode "dim" 1; insertObject "¥¥dim"}
  2648. proc exp {} {checkMathMode "exp" 1; insertObject "¥¥exp"}
  2649. proc gcd {} {checkMathMode "gcd" 1; insertObject "¥¥gcd"}
  2650. proc hom {} {checkMathMode "hom" 1; insertObject "¥¥hom"}
  2651. # proc inf {} {checkMathMode "inf" 1; insertObject "¥¥inf"}
  2652. proc inf {} {
  2653.     checkMathMode "inf" 1
  2654.     if {[wrapObject "¥¥inf_{" "}・"]} then {
  2655.         message "limit set"
  2656.     } else {
  2657.         message "enter limit"
  2658.     }
  2659. }
  2660. proc ker {} {checkMathMode "ker" 1; insertObject "¥¥ker"}
  2661. proc lg {} {checkMathMode "lg" 1; insertObject "¥¥lg"}
  2662. # proc lim {} {checkMathMode "lim" 1; insertObject "¥¥lim"}
  2663. proc lim {} {
  2664.     checkMathMode "lim" 1
  2665.     if {[wrapObject "¥¥lim_{" "}・"]} then {
  2666.         message "limit set"
  2667.     } else {
  2668.         message "enter limit"
  2669.     }
  2670. }
  2671. # proc liminf {} {checkMathMode "liminf" 1; insertObject "¥¥liminf"}
  2672. proc liminf {} {
  2673.     checkMathMode "liminf" 1
  2674.     if {[wrapObject "¥¥liminf_{" "}・"]} then {
  2675.         message "limit set"
  2676.     } else {
  2677.         message "enter limit"
  2678.     }
  2679. }
  2680. # proc limsup {} {checkMathMode "limsup" 1; insertObject "¥¥limsup"}
  2681. proc limsup {} {
  2682.     checkMathMode "limsup" 1
  2683.     if {[wrapObject "¥¥limsup_{" "}・"]} then {
  2684.         message "limit set"
  2685.     } else {
  2686.         message "enter limit"
  2687.     }
  2688. }
  2689. proc ln {} {checkMathMode "ln" 1; insertObject "¥¥ln"}
  2690. proc log {} {checkMathMode "log" 1; insertObject "¥¥log"}
  2691. # proc max {} {checkMathMode "max" 1; insertObject "¥¥max"}
  2692. proc max {} {
  2693.     checkMathMode "max" 1
  2694.     if {[wrapObject "¥¥max_{" "}・"]} then {
  2695.         message "limit set"
  2696.     } else {
  2697.         message "enter limit"
  2698.     }
  2699. }
  2700. # proc min {} {checkMathMode "min" 1; insertObject "¥¥min"}
  2701. proc min {} {
  2702.     checkMathMode "min" 1
  2703.     if {[wrapObject "¥¥min_{" "}・"]} then {
  2704.         message "limit set"
  2705.     } else {
  2706.         message "enter limit"
  2707.     }
  2708. }
  2709. proc Pr {} {checkMathMode "Pr" 1; insertObject "¥¥Pr"}
  2710. proc sec {} {checkMathMode "sec" 1; insertObject "¥¥sec"}
  2711. proc sin {} {checkMathMode "sin" 1; insertObject "¥¥sin"}
  2712. proc sinh {} {checkMathMode "sinh" 1; insertObject "¥¥sinh"}
  2713. # proc sup {} {checkMathMode "sup" 1; insertObject "¥¥sup"}
  2714. proc sup {} {
  2715.     checkMathMode "sup" 1
  2716.     if {[wrapObject "¥¥sup_{" "}・"]} then {
  2717.         message "limit set"
  2718.     } else {
  2719.         message "enter limit"
  2720.     }
  2721. }
  2722. proc tan {} {checkMathMode "tan" 1; insertObject "¥¥tan"}
  2723. proc tanh {} {checkMathMode "tanh" 1; insertObject "¥¥tanh"}
  2724.  
  2725. proc bmod {} {checkMathMode "bmod" 1; insertObject "¥¥bmod"}
  2726. proc pmod {} {
  2727.     checkMathMode "pmod" 1
  2728.     if {[wrapObject "¥¥pmod{" "}・"]} then {
  2729.         message "parenthesized mod set"
  2730.     } else {
  2731.         message "enter formula"
  2732.     }
  2733. }
  2734.  
  2735. #--------------------------------------------------------------------------
  2736. # Large Ops:
  2737. #--------------------------------------------------------------------------
  2738.  
  2739. proc insertLargeOp {commandName} {
  2740.     checkMathMode "$commandName" 1
  2741.     set currentPos [getPos]
  2742.     insertObject "¥¥$commandName¥_{・}^{・}・"
  2743.     goto $currentPos
  2744.     nextTabStop
  2745. }
  2746. proc sum {} {insertLargeOp "sum"}
  2747. proc prod {} {insertLargeOp "prod"}
  2748. proc coprod {} {insertLargeOp "coprod"}
  2749. proc int {} {insertLargeOp "int"}
  2750. proc oint {} {insertLargeOp "oint"}
  2751. proc bigcap {} {insertLargeOp "bigcap"}
  2752. proc bigcup {} {insertLargeOp "bigcup"}
  2753. proc bigsqcup {} {insertLargeOp "bigsqcup"}
  2754. proc bigvee {} {insertLargeOp "bigvee"}
  2755. proc bigwedge {} {insertLargeOp "bigwedge"}
  2756. proc bigodot {} {insertLargeOp "bigodot"}
  2757. proc bigotimes {} {insertLargeOp "bigotimes"}
  2758. proc bigoplus {} {insertLargeOp "bigoplus"}
  2759. proc biguplus {} {insertLargeOp "biguplus"}
  2760.  
  2761. #--------------------------------------------------------------------------
  2762. # Delimiters:
  2763. #--------------------------------------------------------------------------
  2764.  
  2765. proc delimitObject {leftDelim rightDelim} {
  2766.     if {[wrapObject $leftDelim $rightDelim]} then {
  2767.         message "formula delimited"
  2768.     } else {
  2769.         message "enter formula"
  2770.     }
  2771. }
  2772. proc parentheses {} { checkMathMode "parentheses" 1; delimitObject "(" ")・" }
  2773. proc brackets {} { checkMathMode "brackets" 1; delimitObject "¥[" "¥]・" }
  2774. proc braces {} { checkMathMode "braces" 1; delimitObject "¥¥¥{" "¥¥¥}・" }
  2775. proc absoluteValue {} { checkMathMode "absoluteValue" 1; delimitObject "|" "|・" }
  2776. proc getDelims {} {
  2777.     catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" ¥
  2778.                   "brackets" "braces" "angle brackets" "vertical bars" ¥
  2779.                   "double bars" "ceiling" "floor"} delimType
  2780.     if {$delimType != "cancel"} then {
  2781.         switch $delimType {
  2782.             "parentheses" {
  2783.                 set leftDelim "("
  2784.                 set rightDelim ")"
  2785.             }
  2786.             "brackets" {
  2787.                 set leftDelim "¥["
  2788.                 set rightDelim "¥]"
  2789.             }
  2790.             "braces" {
  2791.                 set leftDelim "¥¥¥{"
  2792.                 set rightDelim "¥¥¥}"
  2793.             }
  2794.             "vertical bars" {
  2795.                 set leftDelim "|"
  2796.                 set rightDelim "|"
  2797.             }
  2798.             "double bars" {
  2799.                 set leftDelim "¥¥|"
  2800.                 set rightDelim "¥¥|"
  2801.             }
  2802.             "angle brackets" {
  2803.                 set leftDelim "¥¥langle"
  2804.                 set rightDelim "¥¥rangle"
  2805.             }
  2806.             "ceiling" {
  2807.                 set leftDelim "¥¥lceil"
  2808.                 set rightDelim "¥¥rceil"
  2809.             }
  2810.             "floor" {
  2811.                 set leftDelim "¥¥lfloor"
  2812.                 set rightDelim "¥¥rfloor"
  2813.             }
  2814.             default {
  2815.                 alertnote "¥"$delimType¥" not recognized"
  2816.                 return ""
  2817.             }
  2818.         }
  2819.         return [list $leftDelim $rightDelim]
  2820.     } else {return ""}
  2821. }
  2822. proc otherDelims {} {
  2823.     checkMathMode "otherDelims" 1
  2824.     set delims [getDelims]
  2825.     if {$delims != ""} then {
  2826.         set leftDelim [lindex $delims 0]
  2827.         set rightDelim [lindex $delims 1]
  2828.         delimitObject "$leftDelim" "$rightDelim・"
  2829.     }
  2830. }
  2831. proc {half-openInterval} {} {
  2832.     checkMathMode "half-openInterval" 1; delimitObject "(" "¥]・"
  2833. }
  2834. proc {half-closedInterval} {} {
  2835.     checkMathMode "half-closedInterval" 1; delimitObject "¥[" ")・"
  2836. }
  2837.  
  2838. proc insertBigDelims {leftDelim rightDelim isMultiline} {
  2839.     checkMathMode "insertBigDelims" 1
  2840.     if {$isMultiline} then {
  2841.         doWrapStructure $leftDelim "" $rightDelim
  2842.     } else {
  2843.         if { [wrapObject $leftDelim $rightDelim] } then {
  2844.             message "formula delimited"
  2845.         } else {
  2846.             message "enter formula"
  2847.         }
  2848.     }
  2849. }
  2850. proc bigParens {} {
  2851.     checkMathMode "bigParens" 1; insertBigDelims "¥¥left(" "¥¥right)・" 0
  2852. }
  2853. proc multiBigParens {} {
  2854.     checkMathMode "multiBigParens" 1; insertBigDelims "¥¥left(" "¥¥right)・" 1
  2855. }
  2856. proc bigBrackets {} {
  2857.     checkMathMode "bigBrackets" 1; insertBigDelims "¥¥left¥[" "¥¥right¥]・" 0
  2858. }
  2859. proc multiBigBrackets {} {
  2860.     checkMathMode "multiBigBrackets" 1; insertBigDelims "¥¥left¥[" "¥¥right¥]・" 1
  2861. }
  2862. proc bigBraces {} {
  2863.     checkMathMode "bigBraces" 1; insertBigDelims "¥¥left¥¥¥{" "¥¥right¥¥¥}・" 0
  2864. }
  2865. proc multiBigBraces {} {
  2866.     checkMathMode "multiBigBraces" 1; insertBigDelims "¥¥left¥¥¥{" "¥¥right¥¥¥}・" 1
  2867. }
  2868. proc bigAbsValue {} {
  2869.     checkMathMode "bigAbsValue" 1; insertBigDelims "¥¥left|" "¥¥right|・" 0
  2870. }
  2871. proc multiBigAbsValue {} {
  2872.     checkMathMode "multiBigAbsValue" 1; insertBigDelims "¥¥left|" "¥¥right|・" 1
  2873. }
  2874. proc doOtherBigDelims {name isMultiline} {
  2875.     checkMathMode $name 1
  2876.     set delims [getDelims]
  2877.     if {$delims != ""} then {
  2878.         append leftDelim "¥¥left" [lindex $delims 0]
  2879.         append rightDelim "¥¥right" [lindex $delims 1]
  2880.         insertBigDelims "$leftDelim" "$rightDelim・" $isMultiline
  2881.     }
  2882. }
  2883. proc otherBigDelims {} {
  2884.     doOtherBigDelims "otherBigDelims" 0
  2885. }
  2886. proc otherMultiBigDelims {} {
  2887.     doOtherBigDelims "otherMultiBigDelims" 1
  2888. }
  2889. proc bigLeftBrace {} {
  2890.     checkMathMode "bigLeftBrace" 1
  2891.     insertBigDelims "¥¥left¥¥¥{" "¥¥right.・" 0
  2892. }
  2893. proc multiBigLeftBrace {} {
  2894.     checkMathMode "multiBigLeftBrace" 1
  2895.     insertBigDelims "¥¥left¥¥¥{" "¥¥right.・" 1
  2896. }
  2897. proc doOtherMixedBigDelims {name isMultiline} {
  2898.     checkMathMode $name 1
  2899.     catch {prompt "Choose LEFT delimiter:" "parenthesis" "" "parenthesis" ¥
  2900.                   "bracket" "brace" "vertical bar" "double bar" ¥
  2901.                   "angle bracket" "ceiling" "floor" "slash" "backslash" ¥
  2902.                   "none"} delimType
  2903.     if {$delimType != "cancel"} then {
  2904.         switch $delimType {
  2905.             "parenthesis" {set leftDelim "("}
  2906.             "bracket" {set leftDelim "¥["}
  2907.             "brace" {set leftDelim "¥¥¥{"}
  2908.             "vertical bar" {set leftDelim "|"}
  2909.             "double bar" {set leftDelim "¥¥|"}
  2910.             "angle bracket" {set leftDelim "¥¥langle"}
  2911.             "ceiling" {set leftDelim "¥¥lceil"}
  2912.             "floor" {set leftDelim "¥¥lfloor"}
  2913.             "slash" {set leftDelim "/"}
  2914.             "backslash" {set leftDelim "¥¥backslash"}
  2915.             "none" {set leftDelim "."}
  2916.             default {
  2917.                 alertnote "¥"$delimType¥" not recognized"
  2918.                 return
  2919.             }
  2920.         }
  2921.         catch {prompt "Choose RIGHT delimiter:" "parenthesis" "" "parenthesis" ¥
  2922.                       "bracket" "brace" "vertical bar" "double bar" ¥
  2923.                       "angle bracket" "ceiling" "floor" "slash" "backslash" ¥
  2924.                       "none"} delimType
  2925.         if {$delimType != "cancel"} then {
  2926.             switch $delimType {
  2927.                 "parenthesis" {set rightDelim ")"}
  2928.                 "bracket" {set rightDelim "¥]"}
  2929.                 "brace" {set rightDelim "¥¥¥}"}
  2930.                 "vertical bar" {set rightDelim "|"}
  2931.                 "double bar" {set rightDelim "¥¥|"}
  2932.                 "angle bracket" {set rightDelim "¥¥rangle"}
  2933.                 "ceiling" {set rightDelim "¥¥rceil"}
  2934.                 "floor" {set rightDelim "¥¥rfloor"}
  2935.                 "slash" {set rightDelim "/"}
  2936.                 "backslash" {set rightDelim "¥¥backslash"}
  2937.                 "none" {set rightDelim "."}
  2938.                 default {
  2939.                     alertnote "¥"$delimType¥" not recognized"
  2940.                     return
  2941.                 }
  2942.             }
  2943.             insertBigDelims "¥¥left$leftDelim" "¥¥right$rightDelim・" $isMultiline
  2944.         }
  2945.     }
  2946. }
  2947. proc otherMixedBigDelims {} {
  2948.     doOtherMixedBigDelims "otherMixedBigDelims" 0
  2949. }
  2950. proc otherMultiMixedBigDelims {} {
  2951.     doOtherMixedBigDelims "otherMultiMixedBigDelims" 1
  2952. }
  2953.  
  2954. #--------------------------------------------------------------------------
  2955. # Accents:
  2956. #--------------------------------------------------------------------------
  2957.  
  2958. proc acute {} {
  2959.     checkMathMode "acute" 1
  2960.     if {[isSelection] > 1} then {
  2961.         alertnote "Warning: only a single character may be accented!"
  2962.     }
  2963.     if {[wrapObject "¥¥acute{" "}・"]} then {
  2964.         message "accent set"
  2965.     } else {
  2966.         message "enter one character"
  2967.     }
  2968. }
  2969. proc bar {} {
  2970.     checkMathMode "bar" 1
  2971.     if {[isSelection] > 1} then {
  2972.         alertnote "Warning: only a single character may be accented!"
  2973.     }
  2974.     if {[wrapObject "¥¥bar{" "}・"]} then {
  2975.         message "accent set"
  2976.     } else {
  2977.         message "enter one character"
  2978.     }
  2979. }
  2980. proc breve {} {
  2981.     checkMathMode "breve" 1
  2982.     if {[isSelection] > 1} then {
  2983.         alertnote "Warning: only a single character may be accented!"
  2984.     }
  2985.     if {[wrapObject "¥¥breve{" "}・"]} then {
  2986.         message "accent set"
  2987.     } else {
  2988.         message "enter one character"
  2989.     }
  2990. }
  2991. proc check {} {
  2992.     checkMathMode "check" 1
  2993.     if {[isSelection] > 1} then {
  2994.         alertnote "Warning: only a single character may be accented!"
  2995.     }
  2996.     if {[wrapObject "¥¥check{" "}・"]} then {
  2997.         message "accent set"
  2998.     } else {
  2999.         message "enter one character"
  3000.     }
  3001. }
  3002. proc dot {} {
  3003.     checkMathMode "dot" 1
  3004.     if {[isSelection] > 1} then {
  3005.         alertnote "Warning: only a single character may be accented!"
  3006.     }
  3007.     if {[wrapObject "¥¥dot{" "}・"]} then {
  3008.         message "accent set"
  3009.     } else {
  3010.         message "enter one character"
  3011.     }
  3012. }
  3013. proc ddot {} {
  3014.     checkMathMode "ddot" 1
  3015.     if {[isSelection] > 1} then {
  3016.         alertnote "Warning: only a single character may be accented!"
  3017.     }
  3018.     if {[wrapObject "¥¥ddot{" "}・"]} then {
  3019.         message "accent set"
  3020.     } else {
  3021.         message "enter one character"
  3022.     }
  3023. }
  3024. proc grave {} {
  3025.     checkMathMode "grave" 1
  3026.     if {[isSelection] > 1} then {
  3027.         alertnote "Warning: only a single character may be accented!"
  3028.     }
  3029.     if {[wrapObject "¥¥grave{" "}・"]} then {
  3030.         message "accent set"
  3031.     } else {
  3032.         message "enter one character"
  3033.     }
  3034. }
  3035. proc hat {} {
  3036.     checkMathMode "hat" 1
  3037.     if {[isSelection] > 1} then {
  3038.         alertnote "Warning: only a single character may be accented!"
  3039.     }
  3040.     if {[wrapObject "¥¥hat{" "}・"]} then {
  3041.         message "accent set"
  3042.     } else {
  3043.         message "enter one character"
  3044.     }
  3045. }
  3046. proc tilde {} {
  3047.     checkMathMode "tilde" 1
  3048.     if {[isSelection] > 1} then {
  3049.         alertnote "Warning: only a single character may be accented!"
  3050.     }
  3051.     if {[wrapObject "¥¥tilde{" "}・"]} then {
  3052.         message "accent set"
  3053.     } else {
  3054.         message "enter one character"
  3055.     }
  3056. }
  3057. proc vec {} {
  3058.     checkMathMode "vec" 1
  3059.     if {[isSelection] > 1} then {
  3060.         alertnote "Warning: only a single character may be accented!"
  3061.     }
  3062.     if {[wrapObject "¥¥vec{" "}・"]} then {
  3063.         message "accent set"
  3064.     } else {
  3065.         message "enter one character"
  3066.     }
  3067. }
  3068.  
  3069. proc widehat {} {
  3070.     checkMathMode "widehat" 1
  3071.     if {[isSelection] > 3} then {
  3072.         alertnote "Warning: only a few characters may be accented!"
  3073.     }
  3074.     if {[wrapObject "¥¥widehat{" "}・"]} then {
  3075.         message "accent set"
  3076.     } else {
  3077.         message "enter a few characters"
  3078.     }
  3079. }
  3080. proc widetilde {} {
  3081.     checkMathMode "widetilde" 1
  3082.     if {[isSelection] > 3} then {
  3083.         alertnote "Warning: only a few characters may be accented!"
  3084.     }
  3085.     if {[wrapObject "¥¥widetilde{" "}・"]} then {
  3086.         message "accent set"
  3087.     } else {
  3088.         message "enter a few characters"
  3089.     }
  3090. }
  3091.  
  3092. proc imath {} {checkMathMode "imath" 1; insertObject "¥¥imath"}
  3093. proc jmath {} {checkMathMode "jmath" 1; insertObject "¥¥jmath"}
  3094.  
  3095. #--------------------------------------------------------------------------
  3096. # Grouping:
  3097. #--------------------------------------------------------------------------
  3098.  
  3099. proc underline {} {
  3100.     checkMathMode "underline" 1
  3101.     if {[wrapObject "¥¥underline{" "}・"]} then {
  3102.         message "selection underlined"
  3103.     } else {
  3104.         message "enter text"
  3105.     }
  3106. }
  3107. proc overline {} {
  3108.     checkMathMode "overline" 1
  3109.     if {[wrapObject "¥¥overline{" "}・"]} then {
  3110.         message "selection overlined"
  3111.     } else {
  3112.         message "enter text"
  3113.     }
  3114. }
  3115. proc underbrace {} {
  3116.     checkMathMode "underbrace" 1
  3117.     if {[wrapObject "¥¥underbrace{" "}・"]} then {
  3118.         message "selection underbraced"
  3119.     } else {
  3120.         message "enter text"
  3121.     }
  3122. }
  3123. proc overbrace {} {
  3124.     checkMathMode "overbrace" 1
  3125.     if {[wrapObject "¥¥overbrace{" "}・"]} then {
  3126.         message "selection overbraced"
  3127.     } else {
  3128.         message "enter text"
  3129.     }
  3130. }
  3131. proc overrightarrow {} {
  3132.     checkMathMode "overrightarrow" 1
  3133.     if {[wrapObject "¥¥overrightarrow{" "}・"]} then {
  3134.         message "selection overrightarrowed"
  3135.     } else {
  3136.         message "enter text"
  3137.     }
  3138. }
  3139. proc overleftarrow {} {
  3140.     checkMathMode "overleftarrow" 1
  3141.     if {[wrapObject "¥¥overleftarrow{" "}・"]} then {
  3142.         message "selection overleftarrowed"
  3143.     } else {
  3144.         message "enter text"
  3145.     }
  3146. }
  3147. proc stackrel {} {
  3148.     checkMathMode "stackrel" 1
  3149.     set currentPos [getPos]
  3150.     if {[insertObject "¥¥stackrel{・}{・}・"]} then {
  3151.         goto $currentPos
  3152.         nextTabStop
  3153.         message "1st arg scriptstyle"
  3154.     }
  3155. }
  3156.  
  3157. #--------------------------------------------------------------------------
  3158. # Spacing:
  3159. #--------------------------------------------------------------------------
  3160.  
  3161. proc negThin {} {checkMathMode "negThin" 1; insertObject "¥¥!"}
  3162. proc thin {} {checkMathMode "thin" 1; insertObject "¥¥,"}
  3163. proc medium {} {checkMathMode "medium" 1; insertObject "¥¥:"}
  3164. proc thick {} {checkMathMode "thick" 1; insertObject "¥¥;"}
  3165. proc quad {} {checkMathMode "quad" 1; insertObject "¥¥quad"}
  3166. proc qquad {} {checkMathMode "qquad" 1; insertObject "¥¥qquad"}
  3167. proc hspace {} {
  3168.     checkMathMode "hspace" 1
  3169.     if {[wrapObject "¥¥hspace{" "}・"]} then {
  3170.         message "spacing set"
  3171.     } else {
  3172.         message "enter the desired horizontal spacing"
  3173.     }
  3174. }
  3175. proc vspace {} {
  3176.     checkMathMode "vspace" 1
  3177.     if {[wrapObject "¥¥vspace{" "}・"]} then {
  3178.         message "spacing set"
  3179.     } else {
  3180.         message "enter the desired horizontal spacing"
  3181.     }
  3182. }
  3183. proc hfill {} {checkMathMode "hfill" 1; insertObject "¥¥hfill"}
  3184. proc vfill {} {checkMathMode "vfill" 1; insertObject "¥¥vfill"}
  3185. proc smallskip {} {checkMathMode "smallskip" 1; insertObject "¥¥smallskip"}
  3186. proc medskip {} {checkMathMode "medskip" 1; insertObject "¥¥medskip"}
  3187. proc bigskip {} {checkMathMode "bigskip" 1; insertObject "¥¥bigskip"}
  3188.  
  3189.